﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using CMISLibrary;
using BCNPCObject;
using BCNPCObject.DB;
using System.Data.OracleClient;
using System.Windows;
using System.Windows.Forms;

namespace bus_TienichNPC
{
    public class cls_TienichNPC_bus
    {
        #region   Atributes
        private cls_D_DVI_QLY_Controller obj_DD_DVI_QLY_Controller;
        private cls_NPC_BCTTCC_Controller obj_NPC_BCTTCC_Controller;
        private cls_NPC_BCTSKT_Controller obj_NPC_BCTSKT_Controller;
        private cls_NPC_BCTTTT_Controller obj_NPC_BCTTTT_Controller;
        private cls_NPC_BCTTDD_Controller obj_NPC_BCTTDD_Controller;
        private cls_NPC_KHTTTT_Controller obj_NPC_KHTTTT_Controller;
        private cls_NPC_KHTTCC_Controller obj_NPC_KHTTCC_Controller;
        private cls_NPC_BCKD07_Controller obj_NPC_BCKD07_Controller;
        private cls_PC1_BCKD11_Controller obj_PC1_BCKD11_Controller;
        private cls_PC1_BCKD16_Controller obj_PC1_BCKD16_Controller;
        private cs_pc1_bieu18_Controller obj_pc1_bieu18_Controller;
        private cs_pc1_bieu17_Controller obj_pc1_bieu17_Controller;
        private cls_D_TRAM_Controller obj_D_TRAM_Controller;
        private cls_D_LO_Controller obj_D_LO_Controller;
        private cls_D_TO_Controller obj_D_TO_Controller;
        private cls_D_CAP_DAP_Controller obj_D_CAP_DAP_Controller;
        private cls_NPC_BCKD00_Controller obj_pc1_bieu00_Controller;
        private cls_PC1_BCKD_4A_Controller obj_PC1_BCKD_4A_Controller;
        private cls_PC1_BCKD_4B_Controller obj_PC1_BCKD_4B_Controller;
        private cls_NGC_Bieu01_Controller obj_PC1_NGC_BIEU01_Controller;
        private cls_NGC_Bieu02_Controller obj_PC1_NGC_BIEU02_Controller;
        private cls_NGC_Bieu03_Controller obj_PC1_NGC_BIEU03_Controller;
        private cls_NGC_Bieu04_Controller obj_PC1_NGC_BIEU04_Controller;
        private cls_NGC_Bieu05_Controller obj_PC1_NGC_BIEU05_Controller;
        private cls_PC1_BIABC_Controller obj_PC1_BIABC_Controller;
        private cls_PC1_BCKD_5A_Controller obj_PC1_BCKD_5A_Controller;
        private cls_PC1_BCKD_5B_Controller obj_PC1_BCKD_5B_Controller;
        private cls_NPC_INTOGCS_Controller obj_NPC_INTOGCS_Controller;
        private cls_TRUY_THU_Controller obj_TRUY_THU_Controller;
        private cls_NPC_TRTH_CHISO_Controller obj_NPC_TRTH_CHISO_Controller;
        private cls_NPC_TRTH_DDO_Controller obj_NPC_TRTH_DDO_Controller;
        private cls_NPC_TRTH_KHANG_Controller obj_NPC_TRTH_KHANG_Controller;
        private cls_CN_THEODOINO_Controller obj_CN_THEODOINO_Controller;
        private cls_CN_PHIEU_THU_Controller obj_CN_PHIEU_THU_Controller;
        private cls_CN_HDON_PHTHU_Controller obj_CN_HDON_PHTHU_Controller;
        private cls_CN_BB_GTHU_Controller obj_CN_BB_GTHU_Controller;
        private cls_CN_HDON_GTHU_Controller obj_CN_HDON_GTHU_Controller;
        private cls_NPC_HDON_TKHOAN_Controller obj_NPC_HDON_TKHOAN_Controller;
        private cls_NPC_LOG_CHAMNO_Controller obj_NPC_LOG_CHAMNO_Controller;
        private cls_NPC_INTOGCS_DNGUON_Controller obj_NPC_INTOGCS_DNGUON_Controller;
        private cls_NPC_CHAMNO_OFFLINE_Controller obj_NPC_CHAMNO_OFFLINE_Controller;
        

        # endregion
        #region   Constructor

        public cls_TienichNPC_bus()
        {
            obj_DD_DVI_QLY_Controller = new cls_D_DVI_QLY_Controller();
            obj_NPC_BCTTCC_Controller = new cls_NPC_BCTTCC_Controller();
            obj_NPC_BCTSKT_Controller = new cls_NPC_BCTSKT_Controller();
            obj_NPC_BCTTTT_Controller = new cls_NPC_BCTTTT_Controller();
            obj_NPC_BCTTDD_Controller = new cls_NPC_BCTTDD_Controller();
            obj_NPC_KHTTTT_Controller = new cls_NPC_KHTTTT_Controller();
            obj_NPC_KHTTCC_Controller = new cls_NPC_KHTTCC_Controller();
            obj_NPC_BCKD07_Controller = new cls_NPC_BCKD07_Controller();
            obj_PC1_BCKD11_Controller = new cls_PC1_BCKD11_Controller();
            obj_PC1_BCKD16_Controller = new cls_PC1_BCKD16_Controller();
            obj_pc1_bieu17_Controller = new cs_pc1_bieu17_Controller();
            obj_pc1_bieu18_Controller = new cs_pc1_bieu18_Controller();
            obj_D_TRAM_Controller = new cls_D_TRAM_Controller();
            obj_D_LO_Controller = new cls_D_LO_Controller();
            obj_D_TO_Controller = new cls_D_TO_Controller();
            obj_D_CAP_DAP_Controller = new cls_D_CAP_DAP_Controller();
            obj_pc1_bieu00_Controller = new cls_NPC_BCKD00_Controller();
            obj_PC1_BCKD_4A_Controller = new cls_PC1_BCKD_4A_Controller();
            obj_PC1_BCKD_4B_Controller = new cls_PC1_BCKD_4B_Controller();
            obj_PC1_NGC_BIEU01_Controller = new cls_NGC_Bieu01_Controller();
            obj_PC1_NGC_BIEU02_Controller = new cls_NGC_Bieu02_Controller();
            obj_PC1_NGC_BIEU03_Controller = new cls_NGC_Bieu03_Controller();
            obj_PC1_NGC_BIEU04_Controller = new cls_NGC_Bieu04_Controller();
            obj_PC1_NGC_BIEU05_Controller = new cls_NGC_Bieu05_Controller();
            obj_PC1_BIABC_Controller = new cls_PC1_BIABC_Controller();
            obj_PC1_BCKD_5A_Controller = new cls_PC1_BCKD_5A_Controller();
            obj_PC1_BCKD_5B_Controller = new cls_PC1_BCKD_5B_Controller();
            obj_NPC_INTOGCS_Controller = new cls_NPC_INTOGCS_Controller();
            obj_TRUY_THU_Controller = new cls_TRUY_THU_Controller();
            obj_CN_THEODOINO_Controller = new cls_CN_THEODOINO_Controller();
            obj_CN_PHIEU_THU_Controller = new cls_CN_PHIEU_THU_Controller();
            obj_CN_HDON_PHTHU_Controller = new cls_CN_HDON_PHTHU_Controller();
            obj_CN_BB_GTHU_Controller = new cls_CN_BB_GTHU_Controller();
            obj_CN_HDON_GTHU_Controller = new cls_CN_HDON_GTHU_Controller();
            obj_NPC_HDON_TKHOAN_Controller = new cls_NPC_HDON_TKHOAN_Controller();
            obj_NPC_LOG_CHAMNO_Controller = new cls_NPC_LOG_CHAMNO_Controller();
            obj_NPC_INTOGCS_DNGUON_Controller = new cls_NPC_INTOGCS_DNGUON_Controller();
            obj_NPC_CHAMNO_OFFLINE_Controller = new cls_NPC_CHAMNO_OFFLINE_Controller();


        }
        #endregion
        # region Mapinfo
        public void mapinfo_KHTTCC(DataRow dr)
        {
            if(this.obj_NPC_KHTTCC_Controller==null)
            { this.obj_NPC_KHTTCC_Controller = new cls_NPC_KHTTCC_Controller(); }
            this.obj_NPC_KHTTCC_Controller.pInfor.MA_DVIQLY = dr["MA_DVIQLY"].ToString();
            this.obj_NPC_KHTTCC_Controller.pInfor.MA_TRAM = dr["MA_TRAM"].ToString();
            this.obj_NPC_KHTTCC_Controller.pInfor.TTKT_KH = Convert.ToDecimal(dr["TTKT_KH"].ToString());
            this.obj_NPC_KHTTCC_Controller.pInfor.HSNHAN = Convert.ToInt16(dr["HSNHAN"].ToString());
        }

        #region Mapinfo_ATM
        private void MapInfo_GTHU(DataTable dt, long decTongTien, long decTongThue, string strMAtngan, string strManvien, Int32 iCount, DateTime pngaygiao, long psobbangiao)
        {

            // map CN_BB_GTHU
            //CN_BB_GTHU infobb = new CN_BB_GTHU();
            if (this.obj_CN_BB_GTHU_Controller == null)
            {
                this.obj_CN_BB_GTHU_Controller = new cls_CN_BB_GTHU_Controller();
            }
            this.obj_CN_BB_GTHU_Controller.pInfor.MA_DVIQLY = dt.Rows[0]["MA_DVIQLY"].ToString();
            this.obj_CN_BB_GTHU_Controller.pInfor.MA_CNANG = "-2";
            this.obj_CN_BB_GTHU_Controller.pInfor.SO_BBQTOAN = 0;
            this.obj_CN_BB_GTHU_Controller.pInfor.SO_BBGIAO = psobbangiao;
            this.obj_CN_BB_GTHU_Controller.pInfor.MA_TNGAN = strMAtngan;
            this.obj_CN_BB_GTHU_Controller.pInfor.MA_NVIEN = strManvien;
            this.obj_CN_BB_GTHU_Controller.pInfor.NGAY_GIAO = pngaygiao == null ? DateTime.Now : pngaygiao;
            this.obj_CN_BB_GTHU_Controller.pInfor.TSO_TIEN = decTongTien;
            this.obj_CN_BB_GTHU_Controller.pInfor.TSO_GTGT = decTongThue;
            this.obj_CN_BB_GTHU_Controller.pInfor.TSO_HDON = iCount;
            this.obj_CN_BB_GTHU_Controller.pInfor.TSO_TIENQT = 0;
            this.obj_CN_BB_GTHU_Controller.pInfor.TSO_GTGTQT = 0;
            this.obj_CN_BB_GTHU_Controller.pInfor.TSO_HDONQT = 0;
            this.obj_CN_BB_GTHU_Controller.pInfor.NGUOI_TAO = "NPCUS-ATM";
            this.obj_CN_BB_GTHU_Controller.pInfor.NGAY_TAO = DateTime.Now;
            this.obj_CN_BB_GTHU_Controller.pInfor.NGAY_SUA = DateTime.Now;
            this.obj_CN_BB_GTHU_Controller.pInfor.NGUOI_SUA = "NPCUS-ATM";
            this.obj_CN_BB_GTHU_Controller.pInfor.LOAI_BBAN = 0;
            List<CN_HDON_GTHU> infogthu_L = new List<CN_HDON_GTHU>();
            List<CN_THEODOINO> infoCN_L = new List<CN_THEODOINO>();
            foreach (DataRow dr in dt.Rows)
            {
                CN_HDON_GTHU infogthu = new CN_HDON_GTHU();
                CN_THEODOINO infocno = new CN_THEODOINO();
                infogthu.MA_DVIQLY = obj_CN_BB_GTHU_Controller.pInfor.MA_DVIQLY;
                infogthu.ID_HDON = Convert.ToInt64(dr["ID_HDON"]);
                infogthu.LOAI_HDON = dr["LOAI_HDON"].ToString();
                infogthu.SO_BBGIAO = psobbangiao;
                infogthu.SO_BBQTOAN = 0;
                infogthu.SO_TIEN = Convert.ToDecimal(dr["SO_TIEN"]);
                infogthu.TIEN_GTGT = Convert.ToDecimal(dr["TIEN_GTGT"]);
                infogthu.SO_TIENQT = 0;
                infogthu.TIEN_GTGTQT = 0;
                infogthu.MA_SOGCS = dr["MA_SOGCS"].ToString();
                infogthu.NGAY_TAO = this.obj_CN_BB_GTHU_Controller.pInfor.NGAY_TAO;
                infogthu.NGUOI_TAO = this.obj_CN_BB_GTHU_Controller.pInfor.NGUOI_TAO;
                infogthu.NGAY_SUA = this.obj_CN_BB_GTHU_Controller.pInfor.NGAY_SUA;
                infogthu.NGUOI_SUA = this.obj_CN_BB_GTHU_Controller.pInfor.NGUOI_SUA;
                infogthu.MA_CNANG = this.obj_CN_BB_GTHU_Controller.pInfor.MA_CNANG;
                infogthu_L.Add(infogthu);
                // CN_THEODOINO
                infocno.MA_DVIQLY = infogthu.MA_DVIQLY;
                infocno.ID_HDON = infogthu.ID_HDON;
                infocno.LOAI_HDON = infogthu.LOAI_HDON;
                infocno.TTHAI_GIAO = 1;
                infocno.LAN_GIAO = infocno.LAN_GIAO + 1;
                infocno.NGAY_SUA = this.obj_CN_BB_GTHU_Controller.pInfor.NGAY_SUA;
                infocno.NGUOI_SUA = this.obj_CN_BB_GTHU_Controller.pInfor.NGUOI_SUA;
                infocno.MA_CNANG = this.obj_CN_BB_GTHU_Controller.pInfor.MA_CNANG;
                infoCN_L.Add(infocno);
            }
            obj_CN_HDON_GTHU_Controller = new cls_CN_HDON_GTHU_Controller(infogthu_L, 1);
            obj_CN_THEODOINO_Controller = new cls_CN_THEODOINO_Controller(infoCN_L, 1);

        }
        public void mapinfo_CN_THEODOINO(DataRow dr)
        {
            if (this.obj_CN_THEODOINO_Controller == null)
            { this.obj_CN_THEODOINO_Controller = new cls_CN_THEODOINO_Controller(); }
            this.obj_CN_THEODOINO_Controller.pInfor.MA_DVIQLY = dr["MA_DVIQLY"].ToString();
            this.obj_CN_THEODOINO_Controller.pInfor.ID_HDON = Convert.ToInt64(dr["ID_HDON"].ToString());
            this.obj_CN_THEODOINO_Controller.pInfor.LOAI_HDON = dr["LOAI_HDON"].ToString();
            this.obj_CN_THEODOINO_Controller.pInfor.TIEN_NO = Convert.ToDecimal(dr["TIEN_NO"].ToString()) - Convert.ToDecimal(dr["SO_TIEN"].ToString());
            this.obj_CN_THEODOINO_Controller.pInfor.THUE_NO = Convert.ToDecimal(dr["THUE_NO"].ToString()) - Convert.ToDecimal(dr["TIEN_GTGT"].ToString());

        }
        public void mapinfo_NPC_HDON_TKHOAN(DataRow dr, string strUsername)
        {
            if (this.obj_NPC_HDON_TKHOAN_Controller == null)
            { this.obj_NPC_HDON_TKHOAN_Controller = new cls_NPC_HDON_TKHOAN_Controller(); }
            this.obj_NPC_HDON_TKHOAN_Controller.pInfor.MA_DVIQLY = dr["MA_DVIQLY"].ToString();
            this.obj_NPC_HDON_TKHOAN_Controller.pInfor.ID_HDON = Convert.ToInt64(dr["ID_HDON"].ToString());
            this.obj_NPC_HDON_TKHOAN_Controller.pInfor.MA_GD = dr["MA_GD"].ToString();
            this.obj_NPC_HDON_TKHOAN_Controller.pInfor.NGUOI_SUA = strUsername;
        }
        public void mapinfo_NPC_LOG_CHAMNO(DataRow dr, string strUsername, string strMA_ERRO, short itinhtrang, string strMathaotac)
        {
            if (this.obj_NPC_LOG_CHAMNO_Controller == null)
            { this.obj_NPC_LOG_CHAMNO_Controller = new cls_NPC_LOG_CHAMNO_Controller(); }
            this.obj_NPC_LOG_CHAMNO_Controller.pInfor.MA_DVIQLY = dr["MA_DVIQLY"].ToString();
            this.obj_NPC_LOG_CHAMNO_Controller.pInfor.ID_HDON = Convert.ToInt64(dr["ID_HDON"].ToString());
            this.obj_NPC_LOG_CHAMNO_Controller.pInfor.LOAI_HDON = dr["LOAI_HDON"].ToString();
            this.obj_NPC_LOG_CHAMNO_Controller.pInfor.MA_GD = dr["MA_GD"].ToString();
            this.obj_NPC_LOG_CHAMNO_Controller.pInfor.NGUOI_TAO = strUsername;
            this.obj_NPC_LOG_CHAMNO_Controller.pInfor.MA_ERRO = strMA_ERRO;
            this.obj_NPC_LOG_CHAMNO_Controller.pInfor.NGAY_TAO = DateTime.Now;
            this.obj_NPC_LOG_CHAMNO_Controller.pInfor.TINH_TRANG = itinhtrang;
            this.obj_NPC_LOG_CHAMNO_Controller.pInfor.MA_THAOTAC = strMathaotac;

        }
        public void mapinfo_NPC_CHAMNO_OFFLINE(DataRow dr, string strUsername, Int16 ithanght, Int16 inamht)
        {
            if (this.obj_NPC_CHAMNO_OFFLINE_Controller == null)
            { this.obj_NPC_CHAMNO_OFFLINE_Controller = new cls_NPC_CHAMNO_OFFLINE_Controller(); }
            this.obj_NPC_CHAMNO_OFFLINE_Controller.pInfor.MA_DVIQLY = dr["MA_DVIQLY"].ToString();
            this.obj_NPC_CHAMNO_OFFLINE_Controller.pInfor.ID_HDON = Convert.ToInt64(dr["ID_HDON"].ToString());
            this.obj_NPC_CHAMNO_OFFLINE_Controller.pInfor.TIEN_NOP = Convert.ToDecimal(dr["SO_TIEN"].ToString());
            this.obj_NPC_CHAMNO_OFFLINE_Controller.pInfor.THUE_NOP = Convert.ToDecimal(dr["TIEN_GTGT"].ToString());
            this.obj_NPC_CHAMNO_OFFLINE_Controller.pInfor.MA_TNGAN = dr["MA_TNGAN"].ToString();
            this.obj_NPC_CHAMNO_OFFLINE_Controller.pInfor.SO_BBGIAO = Convert.ToInt64(dr["SO_BBGIAO"].ToString());
            this.obj_NPC_CHAMNO_OFFLINE_Controller.pInfor.NGAY_CHAMNO = Convert.ToDateTime(dr["NGAY_NOP"]);
            this.obj_NPC_CHAMNO_OFFLINE_Controller.pInfor.THANG_HT = ithanght;
            this.obj_NPC_CHAMNO_OFFLINE_Controller.pInfor.NAM_HT = inamht;
            this.obj_NPC_CHAMNO_OFFLINE_Controller.pInfor.NGUOI_TAO = strUsername;
            this.obj_NPC_CHAMNO_OFFLINE_Controller.pInfor.NGAY_TAO = DateTime.Now;

        }
        public void mapinfo_NPC_HDON_TKHOAN_ERRO(DataRow dr)
        {
            if (this.obj_NPC_HDON_TKHOAN_Controller == null)
            { this.obj_NPC_HDON_TKHOAN_Controller = new cls_NPC_HDON_TKHOAN_Controller(); }
            this.obj_NPC_HDON_TKHOAN_Controller.pInfor.MA_DVIQLY = dr["MA_DVIQLY"].ToString();
            this.obj_NPC_HDON_TKHOAN_Controller.pInfor.ID_HDON = Convert.ToInt64(dr["ID_HDON"].ToString());
            this.obj_NPC_HDON_TKHOAN_Controller.pInfor.MA_GD = dr["MA_GD"].ToString();
            this.obj_NPC_HDON_TKHOAN_Controller.pInfor.MA_ERRO = dr["MA_ERRO"].ToString();
        }
        public void mapinfo_CN_PHIEU_THU(DataRow dr, string strMatngan, string strUsername)
        {
            if (this.obj_CN_PHIEU_THU_Controller == null)
            { this.obj_CN_PHIEU_THU_Controller = new cls_CN_PHIEU_THU_Controller(); }
            this.obj_CN_PHIEU_THU_Controller.pInfor.MA_DVIQLY = dr["MA_DVIQLY"].ToString();
            this.obj_CN_PHIEU_THU_Controller.pInfor.MA_KHANG = dr["MA_KHANG"].ToString();
            this.obj_CN_PHIEU_THU_Controller.pInfor.MA_KHTT = dr["MA_KHANG"].ToString();
            this.obj_CN_PHIEU_THU_Controller.pInfor.MA_PTTT = dr["MA_PTTT"].ToString();
            this.obj_CN_PHIEU_THU_Controller.pInfor.MA_TNGAN = strMatngan;
            this.obj_CN_PHIEU_THU_Controller.pInfor.NGAY_NOP = DateTime.Parse(convertDateToShort(dr["NGAY_NOP"].ToString()));
            this.obj_CN_PHIEU_THU_Controller.pInfor.NGAY_SUA = DateTime.Now;
            this.obj_CN_PHIEU_THU_Controller.pInfor.NGAY_TAO = DateTime.Now;
            this.obj_CN_PHIEU_THU_Controller.pInfor.NGUOI_TAO = strUsername;
            this.obj_CN_PHIEU_THU_Controller.pInfor.NGUOI_SUA = strUsername;
            this.obj_CN_PHIEU_THU_Controller.pInfor.SO_BBQTOAN = 0;
            this.obj_CN_PHIEU_THU_Controller.pInfor.SO_TIEN = Convert.ToDecimal(dr["SO_TIEN"]) + Convert.ToDecimal(dr["TIEN_GTGT"]);
            this.obj_CN_PHIEU_THU_Controller.pInfor.TIEN_THUA = 0;
            this.obj_CN_PHIEU_THU_Controller.pInfor.TSO_HDON = 1;
            this.obj_CN_PHIEU_THU_Controller.pInfor.MA_CNANG = "-2";

        }
        public void mapinfo_CN_HDON_PHTHU(DataRow dr, string strMatngan, long _Sophieuthu, string strUsername)
        {
            if (this.obj_CN_HDON_PHTHU_Controller == null)
            { this.obj_CN_HDON_PHTHU_Controller = new cls_CN_HDON_PHTHU_Controller(); }
            this.obj_CN_HDON_PHTHU_Controller.pInfor.MA_DVIQLY = dr["MA_DVIQLY"].ToString();
            this.obj_CN_HDON_PHTHU_Controller.pInfor.SO_PHTHU = _Sophieuthu;
            this.obj_CN_HDON_PHTHU_Controller.pInfor.ID_HDON = Convert.ToInt64(dr["ID_HDON"].ToString());
            this.obj_CN_HDON_PHTHU_Controller.pInfor.MA_PTTT = dr["MA_PTTT"].ToString();
            this.obj_CN_HDON_PHTHU_Controller.pInfor.LOAI_HDON = dr["LOAI_HDON"].ToString();
            this.obj_CN_HDON_PHTHU_Controller.pInfor.MA_TNGAN = strMatngan;
            this.obj_CN_HDON_PHTHU_Controller.pInfor.NGAY_NOP = Convert.ToDateTime(convertDateToShort(dr["NGAY_NOP"].ToString()));
            this.obj_CN_HDON_PHTHU_Controller.pInfor.NGAY_SUA = DateTime.Now;
            this.obj_CN_HDON_PHTHU_Controller.pInfor.NGAY_TAO = DateTime.Now;
            this.obj_CN_HDON_PHTHU_Controller.pInfor.NGUOI_TAO = strUsername;
            this.obj_CN_HDON_PHTHU_Controller.pInfor.NGUOI_SUA = strUsername;
            this.obj_CN_HDON_PHTHU_Controller.pInfor.SO_BBQTOAN = 0;
            this.obj_CN_HDON_PHTHU_Controller.pInfor.TIEN_NOP = Convert.ToDecimal(dr["SO_TIEN"].ToString());
            this.obj_CN_HDON_PHTHU_Controller.pInfor.THUE_NOP = Convert.ToDecimal(dr["TIEN_GTGT"].ToString());
            this.obj_CN_HDON_PHTHU_Controller.pInfor.MA_CNANG = "-2";
        }
        # endregion
        public void mapinfo_KHTTTT(DataRow dr)
        {
            if (this.obj_NPC_KHTTTT_Controller == null)
            { this.obj_NPC_KHTTTT_Controller = new cls_NPC_KHTTTT_Controller(); }
            this.obj_NPC_KHTTTT_Controller.pInfor.MA_DVIQLY = dr["MA_DVIQLY"].ToString();
            this.obj_NPC_KHTTTT_Controller.pInfor.MA_LO = dr["MA_LO"].ToString();
            this.obj_NPC_KHTTTT_Controller.pInfor.TTKT_KH = Convert.ToDecimal(dr["TTKT_KH"].ToString());
            this.obj_NPC_KHTTTT_Controller.pInfor.TIET_DIEN = dr["TIET_DIEN"].ToString();
            this.obj_NPC_KHTTTT_Controller.pInfor.DL_MBA = Convert.ToInt64(dr["DL_MBA"].ToString());
            this.obj_NPC_KHTTTT_Controller.pInfor.CHIEU_DAI = dr["CHIEU_DAI"].ToString();
            this.obj_NPC_KHTTTT_Controller.pInfor.TCHIEU_DAI = dr["TCHIEU_DAI"].ToString();
        }
        public void mapinfo_BCTSKT(DataRow dr)
        {
            if (this.obj_NPC_BCTSKT_Controller == null)
            { this.obj_NPC_BCTSKT_Controller = new cls_NPC_BCTSKT_Controller(); }
            this.obj_NPC_BCTSKT_Controller.pInfor.MA_DVIQLY = dr["MA_DVIQLY"].ToString();
            this.obj_NPC_BCTSKT_Controller.pInfor.MA_LO = dr["MA_LO"].ToString();
            this.obj_NPC_BCTSKT_Controller.pInfor.THANG = Convert.ToInt16 (dr["THANG"].ToString());
            this.obj_NPC_BCTSKT_Controller.pInfor.NAM = Convert.ToInt16(dr["NAM"].ToString());
            this.obj_NPC_BCTSKT_Controller.pInfor.TIET_DIEN = dr["TIET_DIEN"].ToString();
            this.obj_NPC_BCTSKT_Controller.pInfor.TDL_MBA = Convert.ToInt64(dr["TDL_MBA"].ToString());
            this.obj_NPC_BCTSKT_Controller.pInfor.TSO_MBA = Convert.ToInt64(dr["TSO_MBA"].ToString());
            this.obj_NPC_BCTSKT_Controller.pInfor.CHIEU_DAI = dr["CHIEU_DAI"].ToString();
            this.obj_NPC_BCTSKT_Controller.pInfor.TCHIEU_DAI = dr["TCHIEU_DAI"].ToString();
            this.obj_NPC_BCTSKT_Controller.pInfor.SOMBA_CD = Convert.ToInt64(dr["SOMBA_CD"].ToString());
            this.obj_NPC_BCTSKT_Controller.pInfor.SOMBA_SC = Convert.ToInt64(dr["SOMBA_SC"].ToString());
            this.obj_NPC_BCTSKT_Controller.pInfor.SOMBA_CC = Convert.ToInt64(dr["SOMBA_CC"].ToString());
            this.obj_NPC_BCTSKT_Controller.pInfor.DLMBA_CD = Convert.ToInt64(dr["DLMBA_CD"].ToString());
            this.obj_NPC_BCTSKT_Controller.pInfor.DLMBA_SC = Convert.ToInt64(dr["DLMBA_SC"].ToString());
            this.obj_NPC_BCTSKT_Controller.pInfor.DLMBA_CC = Convert.ToInt64(dr["DLMBA_CC"].ToString());
        }
        public void mapinfo_BCKD07(DataRow dr)
        {
            if (this.obj_NPC_BCKD07_Controller == null)
            { this.obj_NPC_BCKD07_Controller = new cls_NPC_BCKD07_Controller(); }
            this.obj_NPC_BCKD07_Controller.pInfor.MA_DVIQLY = dr["MA_DVIQLY"].ToString();
            this.obj_NPC_BCKD07_Controller.pInfor.MA_DONVI = dr["MA_DONVI"].ToString();
            this.obj_NPC_BCKD07_Controller.pInfor.THANG = Convert.ToInt16(dr["THANG"].ToString());
            this.obj_NPC_BCKD07_Controller.pInfor.NAM = Convert.ToInt16(dr["NAM"].ToString());
            this.obj_NPC_BCKD07_Controller.pInfor.DIEN_NHAN = Convert.ToInt64(dr["DIEN_NHAN"].ToString());
            this.obj_NPC_BCKD07_Controller.pInfor.DIEN_GIAO = Convert.ToInt64(dr["DIEN_GIAO"].ToString());
            this.obj_NPC_BCKD07_Controller.pInfor.DIEN_TP = Convert.ToInt64(dr["DIEN_TP"].ToString());
            this.obj_NPC_BCKD07_Controller.pInfor.TL_KH = Convert.ToInt64(dr["TL_KH"].ToString());
        }
        public void mapinfo_BCKD00(DataTable dt_bieu00)
        {
            try
            {
                if (this.obj_pc1_bieu00_Controller == null)
                { this.obj_pc1_bieu00_Controller = new cls_NPC_BCKD00_Controller(); }
                List<PC1_BCKD00> info_PCkd00_lst = new List<PC1_BCKD00>();
                foreach (DataRow dr in dt_bieu00.Rows)
                {
                    PC1_BCKD00 info_kd00 = new PC1_BCKD00();
                    info_kd00.MA_DVIQLY = dr["MA_DVIQLY"].ToString();
                    info_kd00.MA_SO = dr["MA_SO"].ToString();
                    info_kd00.NAM = Convert.ToInt32(dr["NAM"].ToString());
                    info_kd00.THANG = Convert.ToInt32(dr["THANG"].ToString());
                    info_kd00.PHANTICH_DANHGIA = dr["PHANTICH_DANHGIA"].ToString();
                    info_kd00.STT = dr["STT"].ToString();
                    info_kd00.THANG_TH = dr["THANG_TH"].ToString().Length==0? 0:Convert.ToDecimal(dr["THANG_TH"].ToString());
                    info_kd00.YKIEN_KHAC = dr["YKIEN_KHAC"].ToString();
                    info_kd00.LUYKE_TH = dr["LUYKE_TH"].ToString().Length == 0 ? 0 : Convert.ToDecimal(dr["LUYKE_TH"].ToString());
                    info_kd00.KH_GIAO = dr["KH_GIAO"].ToString().Length == 0 ? 0 : Convert.ToDecimal(dr["KH_GIAO"].ToString());
                    info_kd00.DVT = dr["DVT"].ToString();
                    info_kd00.DANH_MUC = dr["DANH_MUC"].ToString();
                    info_PCkd00_lst.Add(info_kd00);
                }
                obj_pc1_bieu00_Controller = new cls_NPC_BCKD00_Controller(info_PCkd00_lst, 1);
            }
            catch
            { }

        }
        #endregion
        #region BAOCAO_NPC
        public DataSet get_D_DVIQLY(string strmadvi)
        {
            DataSet ds_DMDV = new DataSet();
            DataTable dt_DMDV = new DataTable();
            try
            {
                ds_DMDV = obj_DD_DVI_QLY_Controller.select_D_DVI_QLY_BYMADVI(strmadvi);
                return ds_DMDV;
            }
            catch
            { return null; }
        }
        public DataSet select_D_DVI_QLY_ALL(string strMadviqly)
        {
            
            try
            {
                return obj_DD_DVI_QLY_Controller.select_D_DVI_QLY_ALL(strMadviqly);
              
            }
            catch
            {
                return null;
            }
        }
        public DataSet get_thang_lviec()
        {
            try
            {
                return obj_NPC_BCTTCC_Controller.Get_thang_lviec();
            }
            catch
            { return null; }
        }

        

        # region IN TO GHI CHI SO DUCNM_P4
        public DataSet TH_INTOGCS(Int16 iNam, Int16 iThang, Int16 iKy, string strMaDviqly, string strMa_SoGCS, string strMa_KHang)
        {
            //
            DataSet dsInToGCS = new DataSet();
            try
            {
                switch (strMaDviqly.Substring(0, 4))
                {
                    //Bac Giang
                    case "PA05":
                        CMIS2.DB.pa05_TongHopDuLieu(iNam, iThang, iKy, strMaDviqly, strMa_SoGCS, strMa_KHang, out dsInToGCS);
                        break;
                    //Tuyen Quang
                    case "PA12":
                        CMIS2.DB.pa12_TongHopDuLieu(iNam, iThang, iKy, strMaDviqly, strMa_SoGCS, strMa_KHang, out dsInToGCS);
                        break;
                    //Nghe An
                    case "PA13":
                        CMIS2.DB.pa13_TongHopDuLieu(iNam, iThang, iKy, strMaDviqly, strMa_SoGCS, strMa_KHang, out dsInToGCS);
                        break;
                    //Son La
                    case "PA15":
                        CMIS2.DB.pa13_TongHopDuLieu(iNam, iThang, iKy, strMaDviqly, strMa_SoGCS, strMa_KHang, out dsInToGCS);
                        break;
                }

                return dsInToGCS;
            }
            catch
            {
                return null;
            }
        }

        public DataSet select_SoGCS(System.String pr_MA_DVIQLY, System.String pr_MA_SOGCS, System.String pr_TEN_SOGCS, System.String pr_NGAY_GHI, System.Int16 pr_SO_KY)
        {
            try
            {
                var sogcs = (from p in CMIS2.DB.D_SOGCS
                             where p.MA_DVIQLY == pr_MA_DVIQLY
                             && (pr_MA_SOGCS == " " || p.MA_SOGCS == pr_MA_SOGCS && pr_MA_SOGCS != " ")
                             && (pr_NGAY_GHI != " " && p.NGAY_GHI.ToUpper().Contains(pr_NGAY_GHI.ToUpper()) || pr_NGAY_GHI == " ")
                             && (pr_SO_KY != -1 || p.SO_KY == pr_SO_KY && pr_SO_KY != -1)
                             && (pr_TEN_SOGCS != " " && p.TEN_SOGCS.ToUpper().Contains(pr_TEN_SOGCS.ToUpper()) || pr_TEN_SOGCS == " ")
                             orderby p.MA_SOGCS
                             select new
                             {
                                 p.MA_DVIQLY,
                                 p.MA_SOGCS,
                                 p.TEN_SOGCS,
                                 p.SO_KY,
                                 p.NGAY_GHI,
                             }).ToList();

                if (sogcs != null && sogcs.Count > 0)
                {
                    DataTable dt = Utility.LINQToDataTable(sogcs);
                    dt.TableName = "D_SOGCS";
                    DataSet ds = new DataSet();
                    ds.Tables.Add(dt);
                    return ds;
                }
                else return null;
            }
            catch
            {
                return null;
            }
        }

        #endregion

        # region Bieu KDDN-09 DUNGNT
        public DataSet TH_KDDN09(Int16 iNam, Int16 iThang, string strMaDviqly)
        {
            String strErr = "";
            DataTable dt = new DataTable();
            dt.TableName = "TONGHOP_BCKD";
            dt.Columns.Add("TIME");
            dt.Columns.Add("LOG");
            dt.AcceptChanges();
            try
            {
                DataRow dr = dt.NewRow();
                dr = dt.NewRow();
                dr["TIME"] = System.DateTime.Now;
                dr["LOG"] = "Bắt đầu tổng hợp biểu KDDN-09";
                dt.Rows.InsertAt(dr, 0);

                dr = dt.NewRow();
                dr["TIME"] = System.DateTime.Now;
                CMIS2.DB.Bckd11(iNam, iThang, strMaDviqly, out strErr);
                if (strErr == "")
                {
                    dr["LOG"] = "Tổng hợp biểu KDDN-09 thành công.";
                }
                else
                {
                    dr["LOG"] = strErr;
                }
                dt.Rows.InsertAt(dr, 0);

                dr = dt.NewRow();
                dr["TIME"] = System.DateTime.Now;
                dr["LOG"] = "Kết thúc tổng hợp biểu KDDN-09";
                dt.Rows.InsertAt(dr, 0);
                dt.AcceptChanges();
                DataSet ds = new DataSet();
                ds.Tables.Add(dt);
                return ds;
            }
            catch
            { return null; }

        }
        public DataSet select_BCKD11(System.String strTEN_DVIQLY, System.String strTEN_CTREN, System.String pr_MA_DVIQLY, System.Int16 intNam, System.Int16 intThang)
        {
            try
            {
                var a = obj_PC1_BCKD11_Controller.select_Data_BCKD11(pr_MA_DVIQLY, intNam, intThang);
                if (a == null)
                {
                    return null;
                }
                var BCKD_IN = from p in a
                              select new
                              {
                                  p.MA_DVIQLY,
                                  p.TEN_DVIQLY,
                                  p.NGAY_GHI,
                                  p.THANG,
                                  p.NAM,
                                  p.SAN_LUONG,
                                  p.TIEN_DIEN_VND,
                                  p.TIEN_THUE_VND,
                                  p.TIEN_DIEN_USD,
                                  p.TIEN_THUE_USD,
                                  p.GHI_CHU,
                                  TEN_CTREN = " ",
                              };
                if (BCKD_IN != null && BCKD_IN.Count() > 0)
                {
                    DataTable dt = Utility.LINQToDataTable(BCKD_IN);
                    dt.TableName = "IN_BCKD";
                    foreach (DataRow dr in dt.Rows)
                    {
                        dr["TEN_DVIQLY"] = strTEN_DVIQLY;
                        dr["TEN_CTREN"] = strTEN_CTREN;
                    }
                    dt.AcceptChanges();
                    DataSet ds = new DataSet();
                    ds.Tables.Add(dt);
                    return ds;
                }
                else
                {
                    return null;
                }
            }
            catch
            {
                return null;
            }
        }
        # endregion

        # region Bieu KDDN-10 DUNGNT
        public void TH_BCTTCC(string p_madonvi, Int16 p_thang, Int16 p_nam)
        {
            
            try
            {
                CMIS2.DB.th_ttcc(p_madonvi, p_thang, p_nam);
                CMIS2.ResetDB();

            }
            catch
            { return; }

        }

        public void TH_BCTTTT(string p_madonvi, Int16 p_thang, Int16 p_nam,string p_nhapth,string p_dncd)
        {

            try
            {
                CMIS2.DB.th_tttt(p_madonvi, p_thang, p_nam, p_nhapth,p_dncd);
                CMIS2.ResetDB();

            }
            catch
            { return; }

        }

        public void TH_BCTTDD(string p_madonvi, Int16 p_thang, Int16 p_nam, string p_nhapth)
        {

            try
            {
                CMIS2.DB.th_ttdd(p_madonvi, p_thang, p_nam,p_nhapth);
                CMIS2.ResetDB();
            }
            catch
            { return; }

        }

        public void TH_BCKD07(string p_madonvi, Int16 p_thang, Int16 p_nam)
        {

            try
            {
                CMIS2.DB.npc_bieu07(p_madonvi, p_thang, p_nam);

            }
            catch
            { return; }

        }

        public bool Capnhat_BCKD07_saunhap(string p_madonvi, Int16 p_thang, Int16 p_nam)
        {

            try
            {
                CMIS2.DB.npc_bieu07_Tinhsaunhap(p_madonvi, p_thang, p_nam);
                return true;
            }
            catch
            { return false; }

        }

        public void CapnhatdstramCC_KH(string p_madonvi)
        {

            try
            {
                CMIS2.DB.CapnhatdstramCC_KH(p_madonvi);

            }
            catch
            { return; }

        }

        public void CapnhatdsloTT_KH(string p_madonvi)
        {

            try
            {
                CMIS2.DB.CapnhatdsloTT_KH(p_madonvi);

            }
            catch
            { return; }

        }

        public DataSet get_bcttcc(string p_madonvi, Int16 p_thang, Int16 p_nam)
        {
            CMIS2.ResetDB();
            DataSet ds_BCTTCC = new DataSet();
            DataTable dt_bcttcc = new DataTable();
            
            try
            {
                var q1 = obj_NPC_BCTTCC_Controller.Get_BCTTCC(p_madonvi, p_thang, p_nam).ToList();
                var q2 = obj_D_TRAM_Controller.Get_D_TRAM(p_madonvi).ToList();
                var q3 = obj_D_TO_Controller.Get_D_TO(p_madonvi).ToList();
                var q4 = obj_NPC_KHTTCC_Controller.Get_NPC_KHTTCC(p_madonvi).ToList();
                var BCTTCC = from p in q1
                             join m in q2
                             on new { p.MA_DVIQLY, p.MA_TRAM } equals new { m.MA_DVIQLY, m.MA_TRAM }
                             join n in q3
                             on new { p.MA_DVIQLY, p.MA_TO } equals new { n.MA_DVIQLY, n.MA_TO } into h1
                             from h in h1.DefaultIfEmpty()
                             join l in q4
                             on new { p.MA_DVIQLY, p.MA_TRAM } equals new { l.MA_DVIQLY, l.MA_TRAM } into l1
                             from u in l1.DefaultIfEmpty()
                             select new
                             {
                                 p.MA_DVIQLY,
                                 p.MA_TRAM,
                                 m.TEN_TRAM,
                                 m.CSUAT_TRAM,
                                 p.MA_TO,
                                 TEN_TO = h ==null? "Không xác đinh":h.TEN_TO,
                                 HSNHAN = u ==null? 0:u.HSNHAN,
                                 p.THANG,
                                 p.NAM,
                                 p.DIEN_DN,
                                 p.DIEN_TP,
                                 p.DIEN_TT,
                                 p.TL_TT,
                                 p.DIEN_DN_LK,
                                 p.DIEN_TP_LK,
                                 p.TL_TT_LK,
                                 p.TT_KH,
                                 p.TT_KH_LK,
                                 p.DIEN_TT_LK,
                                 XBT = p.XBT == 1 ? "Các khu vực đã tiếp nhận" : " Các khu vực còn lại"
                             };
                dt_bcttcc = Utility.LINQToDataTable(BCTTCC);
                dt_bcttcc.TableName = "BCTTCC";
                ds_BCTTCC.Tables.Add(dt_bcttcc);
                return ds_BCTTCC;
            }
            catch
            { return null; }

        }

        public DataSet get_bctttt(string p_madonvi, Int16 p_thang, Int16 p_nam,string p_nhapth)
        {
            CMIS2.ResetDB();
            DataSet ds_BCTTTT = new DataSet();
            DataTable dt_bctttt = new DataTable();
            try
            {

                var q1 = obj_NPC_BCTTTT_Controller.Get_BCTTTT(p_madonvi, p_thang, p_nam, p_nhapth).ToList();
                var q2 = obj_D_LO_Controller.Get_D_LO(p_madonvi).ToList();
                var q3 = obj_D_CAP_DAP_Controller.Get_D_CAP_DAP().ToList();
                var q4 = obj_NPC_KHTTTT_Controller.Get_NPC_KHTTTT(p_madonvi).ToList();
                var q5 = from q in q1
                         join m in q2
                         on new { q.MA_DVIQLY, q.MA_LO } equals new { m.MA_DVIQLY, m.MA_LO }
                         join n in q3
                         on m.MA_CAPDA equals n.MA_CAPDA
                         select new 
                         { 
                             q.MA_DVIQLY,
                             q.MA_LO,
                             m.TEN_LO,
                             m.MA_CAPDA,
                             n.TEN_CAPDA,
                             q.NAM,
                             q.THANG,
                             q.NHAP_THOP,
                             q.DIEN_NHAN,
                             q.DIEN_GIAO,
                             q.DIEN_DNCC,
                             q.DIEN_TPCD,
                             q.DIEN_TP,
                             q.DIEN_TT,
                             q.TL_TT,
                             q.DIEN_NHAN_LK,
                             q.DIEN_GIAO_LK,
                             q.DIEN_DNCC_LK,
                             q.DIEN_TPCD_LK,
                             q.DIEN_TP_LK,
                             q.DIEN_TT_LK,
                             q.TL_TT_LK,
                             q.TLTT_KH,
                             q.TLTT_KH_LK
                         };

                var BCTTTT = from q in q5
                             join m in q4 
                             on new { q.MA_DVIQLY, q.MA_LO } equals new { m.MA_DVIQLY, m.MA_LO } into h
                             from u in h.DefaultIfEmpty()
                             orderby q.MA_LO
                             select new
                             {
                                 q.MA_DVIQLY,
                                 q.MA_LO,
                                 q.TEN_LO,
                                 q.MA_CAPDA,
                                 q.TEN_CAPDA,
                                 q.NAM,
                                 q.THANG,
                                 q.NHAP_THOP,
                                 q.DIEN_NHAN,
                                 q.DIEN_GIAO,
                                 q.DIEN_DNCC,
                                 q.DIEN_TPCD,
                                 q.DIEN_TP,
                                 q.DIEN_TT,
                                 q.TL_TT,
                                 q.DIEN_NHAN_LK,
                                 q.DIEN_GIAO_LK,
                                 q.DIEN_DNCC_LK,
                                 q.DIEN_TPCD_LK,
                                 q.DIEN_TP_LK,
                                 q.DIEN_TT_LK,
                                 q.TL_TT_LK,
                                 q.TLTT_KH,
                                 q.TLTT_KH_LK,
                                 CHIEU_DAI =u==null? "0":u.CHIEU_DAI,
                                 TIET_DIEN = u == null ? "0" : u.TIET_DIEN,
                                 DL_MBA = u == null ? 0 : u.DL_MBA
                             };
                dt_bctttt = Utility.LINQToDataTable(BCTTTT);
                dt_bctttt.TableName = "BCTTTT";
                ds_BCTTTT.Tables.Add(dt_bctttt);
                return ds_BCTTTT;
            }
            catch
            { return null; }

        }
        public DataSet get_bctskt(string p_madonvi, Int16 p_thang, Int16 p_nam)
        {
            CMIS2.ResetDB();
            DataSet ds_BCTSKT = new DataSet();
            DataTable dt_bctskt = new DataTable();
            try
            {
                var q1 = obj_NPC_BCTSKT_Controller.getNPC_BCTSKT(p_madonvi, p_thang, p_nam).ToList();
                var q2 = obj_D_LO_Controller.Get_D_LO(p_madonvi).ToList();
                var q3 = obj_D_CAP_DAP_Controller.Get_D_CAP_DAP().ToList();
                var BCTSKT = from q in q1
                         join m in q2
                         on new { q.MA_DVIQLY, q.MA_LO } equals new { m.MA_DVIQLY, m.MA_LO }
                         join n in q3
                         on m.MA_CAPDA equals n.MA_CAPDA
                         orderby q.MA_LO
                         select new
                         {
                             q.MA_DVIQLY,
                             q.MA_LO,
                             m.TEN_LO,
                             m.MA_CAPDA,
                             n.TEN_CAPDA,
                             q.NAM,
                             q.THANG,
                             q.TCHIEU_DAI,
                             q.CHIEU_DAI,
                             q.TIET_DIEN,
                             q.TSO_MBA,
                             q.TDL_MBA,
                             q.SOMBA_CD,
                             q.SOMBA_SC,
                             q.SOMBA_CC,
                             q.DLMBA_CD,
                             q.DLMBA_SC,
                             q.DLMBA_CC
                         };
                dt_bctskt = Utility.LINQToDataTable(BCTSKT);
                dt_bctskt.TableName = "BCTSKT";
                ds_BCTSKT.Tables.Add(dt_bctskt);
                return ds_BCTSKT;
            }
            catch
            { return null; }

        }

        public DataSet get_bcttdd(string p_madonvi, Int16 p_thang, Int16 p_nam)
        {
            CMIS2.ResetDB();
            DataSet ds_BCTTDD = new DataSet();
            DataTable dt_bcttdd = new DataTable();

            try
            {
                var q1 = obj_NPC_BCTTDD_Controller.Get_BCTTDD(p_madonvi, p_thang, p_nam).ToList();
                var q2 = obj_D_LO_Controller.Get_D_LO(p_madonvi).ToList();
                var q3 = obj_D_CAP_DAP_Controller.Get_D_CAP_DAP().ToList();
                var q4 = obj_NPC_KHTTTT_Controller.Get_NPC_KHTTTT(p_madonvi).ToList();
                var q5 = from q in q1
                         join m in q2
                         on new { q.MA_DVIQLY, q.MA_LO } equals new { m.MA_DVIQLY, m.MA_LO }
                         join n in q3
                         on m.MA_CAPDA equals n.MA_CAPDA
                         select new
                         {
                             q.MA_DVIQLY,
                             q.MA_LO,
                             m.TEN_LO,
                             m.MA_CAPDA,
                             n.TEN_CAPDA,
                             q.NAM,
                             q.THANG,
                             q.DIEN_NHAN,
                             q.DIEN_GIAO,
                             q.DIEN_TPCC,
                             q.DIEN_TPCD,
                             q.DIEN_TP,
                             q.DIEN_TT,
                             q.TL_TT,
                             q.DIEN_NHAN_LK,
                             q.DIEN_GIAO_LK,
                             q.DIEN_TPCC_LK,
                             q.DIEN_TPCD_LK,
                             q.DIEN_TP_LK,
                             q.DIEN_TT_LK,
                             q.TL_TT_LK,
                             q.TLTT_KT,
                             q.TLTTKT_LK                             
                         };

                var BCTTDD = from q in q5
                             join m in q4
                             on new { q.MA_DVIQLY, q.MA_LO } equals new { m.MA_DVIQLY, m.MA_LO } into h
                             from u in h.DefaultIfEmpty()
                             select new
                             {
                                 q.MA_DVIQLY,
                                 q.MA_LO,
                                 q.TEN_LO,
                                 q.MA_CAPDA,
                                 q.TEN_CAPDA,
                                 q.NAM,
                                 q.THANG,
                                 q.DIEN_NHAN,
                                 q.DIEN_GIAO,
                                 q.DIEN_TPCC,
                                 q.DIEN_TPCD,
                                 q.DIEN_TP,
                                 q.DIEN_TT,
                                 q.TL_TT,
                                 q.DIEN_NHAN_LK,
                                 q.DIEN_GIAO_LK,
                                 q.DIEN_TPCC_LK,
                                 q.DIEN_TPCD_LK,
                                 q.DIEN_TP_LK,
                                 q.DIEN_TT_LK,
                                 q.TL_TT_LK,
                                 q.TLTT_KT,
                                 q.TLTTKT_LK,
                                 CHIEU_DAI = u == null ? "0" : u.CHIEU_DAI,
                                 TIET_DIEN = u == null ? "0" : u.TIET_DIEN,
                                 DL_MBA = u == null ? 0 : u.DL_MBA
                             };
                dt_bcttdd = Utility.LINQToDataTable(BCTTDD);
                dt_bcttdd.TableName = "BCTTDD";
                ds_BCTTDD.Tables.Add(dt_bcttdd);
                return ds_BCTTDD;
            }
            catch
            { return null; }

        }
        public DataSet get_bctt_quy(string p_madonvi, Int16 p_nam, Int16 p_thang, Int16 pbieu, string p_nhapth)
        {
        CMIS2.ResetDB();
        DataSet ds_bctt_quy = new DataSet();
        try
        {
            CMIS2.ResetDB();
            CMIS2.DB.INBIEU10(p_madonvi, p_nam, p_thang, pbieu, p_nhapth, out ds_bctt_quy);
            return ds_bctt_quy;
        }
            catch
        { return null; }

    }

        public DataSet khoitao_BCTSKT(string p_madonvi, Int16 p_thang, Int16 p_nam, Int16 pthangtruoc)
        {
            CMIS2.ResetDB();
            DataSet ds_bctskt= new DataSet();
            try
            {
                CMIS2.ResetDB();
                CMIS2.DB.khoitao_NPC_BCTSKT(p_madonvi, p_thang, p_nam, pthangtruoc,out ds_bctskt);
                ds_bctskt.Tables[0].TableName = "BCTSKT";
                return ds_bctskt;
            }
            catch
            { return null; }

        }
        public DataSet get_bckd07(string p_madonvi, Int16 p_thang, Int16 p_nam)
        {
            DataSet ds_BCKD07 = new DataSet();
            DataTable dt_bckd07 = new DataTable();

            try
            {
               
                var BCKD07 =  from p in obj_NPC_BCKD07_Controller.Get_BCKD07(p_madonvi,p_thang,p_nam) 
                              orderby p.MA_DONVI descending
                             select new
                             {
                                 p.MA_DONVI,
                                 p.TEN_DONVI,
                                 p.CO_IN,
                                 p.DIEN_NHAN,
                                 p.DIEN_GIAO,
                                 p.DIEN_TP,
                                 p.DIEN_TT,
                                 p.TL_TT,
                                 p.TL_KH,
                                 p.DIEN_NHAN_LK,
                                 p.DIEN_GIAO_LK,
                                 p.DIEN_TP_LK,
                                 p.DIEN_TT_LK,
                                 p.TL_TT_LK,
                                 p.TL_KH_LK,
                                 p.MA_DVIQLY,
                                 p.THANG,
                                 p.NAM
                             };
                dt_bckd07 = Utility.LINQToDataTable(BCKD07);
                dt_bckd07.TableName = "BCKD07";
                ds_BCKD07.Tables.Add(dt_bckd07);
                return ds_BCKD07;
            }
            catch
            { return null; }

        }
        
        
        public DataSet Load_KHOACHTRAMCC(string p_madonvi)
        {
            CMIS2.ResetDB();
            DataSet ds_KHTRAMCC = new DataSet();
            DataTable dt_KHTRAMCC = new DataTable();

            try
            {
                var q1 = obj_NPC_KHTTCC_Controller.Get_NPC_KHTTCC(p_madonvi).ToList();
                var q2 = obj_D_TRAM_Controller.Get_D_TRAM(p_madonvi).ToList();
                var KHTRAMCC = from p in q1
                               join m in q2
                               on new { p.MA_DVIQLY, p.MA_TRAM } equals new { m.MA_DVIQLY, m.MA_TRAM }
                               select new
                               {
                                   p.MA_DVIQLY,
                                   p.MA_TRAM,
                                   m.TEN_TRAM,
                                   p.HSNHAN,
                                   p.TTKT_KH
                               };
                dt_KHTRAMCC = Utility.LINQToDataTable(KHTRAMCC);
                dt_KHTRAMCC.TableName = "KHTRAMCC";
                ds_KHTRAMCC.Tables.Add(dt_KHTRAMCC);
                return ds_KHTRAMCC;
            }
            catch
            { return null; }
        }

        public DataSet Load_KHOACHLOTT(string p_madonvi)
        {
            CMIS2.ResetDB();
            DataSet ds_KHLOTT = new DataSet();
            DataTable dt_KHLOTT = new DataTable();

            try
            {
                CMIS2.ResetDB();
                var q1 = obj_NPC_KHTTTT_Controller.Get_NPC_KHTTTT(p_madonvi).ToList();
                var q2 = obj_D_LO_Controller.Get_D_LO(p_madonvi).ToList();
                var KHLOTT = from p in q1 
                             join m in  q2
                             on new { p.MA_DVIQLY, p.MA_LO } equals new { m.MA_DVIQLY, m.MA_LO }
                               select new
                               {
                                   p.MA_DVIQLY,
                                   p.MA_LO,
                                   m.TEN_LO,
                                   p.TIET_DIEN,
                                   p.CHIEU_DAI,
                                   p.DL_MBA,
                                   p.TTKT_KH,
                                   p.TCHIEU_DAI

                               };
                dt_KHLOTT = Utility.LINQToDataTable(KHLOTT);
                dt_KHLOTT.TableName = "KHLOTT";
                ds_KHLOTT.Tables.Add(dt_KHLOTT);
                return ds_KHLOTT;
            }
            catch
            { return null; }
        }
        public bool update_bckd07(DataSet ds)
        {
            string strMaLoi = "";
            try
            {  
                foreach (DataRow dr in ds.Tables["BCKD07_NHAP"].Rows)
                { 
                    mapinfo_BCKD07(dr);
                    if(!obj_NPC_BCKD07_Controller.update_BCKD07())
                    {
                        return false;
                    }
                }
                if (obj_NPC_BCKD07_Controller.submitChange(ref strMaLoi))
                { return true; }
                else { return false; }
                return true;
            }
            catch
            { return false; }
        }
        public bool update_khttcc(DataSet ds)
        {
            string strMaLoi = "";
            try
            {
                foreach (DataRow dr in ds.Tables["KHTTCC"].Rows)
                {
                    mapinfo_KHTTCC(dr);
                    if (!obj_NPC_KHTTCC_Controller.update_KHTTCC())
                    {
                        return false;
                    }
                }
                if (obj_NPC_BCKD07_Controller.submitChange(ref strMaLoi))
                { return true; }
                else { return false; }
                return true;
            }
            catch
            { return false; }
        }
        public bool update_khtttt(DataSet ds)
        {
            string strMaLoi = "";
            try
            {
                foreach (DataRow dr in ds.Tables["KHLOTT"].Rows)
                {
                    mapinfo_KHTTTT(dr);
                    if (!obj_NPC_KHTTTT_Controller.update_KHTTTT())
                    {
                        return false;
                    }
                }
                if (obj_NPC_BCKD07_Controller.submitChange(ref strMaLoi))
                { return true; }
                else { return false; }
                return true;
            }
            catch
            { return false; }
        }
        public bool update_bctskt(DataSet ds)
        {
            string strMaLoi = "";
            try
            {
                foreach (DataRow dr in ds.Tables["BCTSKT"].Rows)
                {
                    mapinfo_BCTSKT(dr);
                    if (!obj_NPC_BCTSKT_Controller.update_BCTSKT())
                    {
                        return false;
                    }
                }
                if (obj_NPC_BCKD07_Controller.submitChange(ref strMaLoi))
                { return true; }
                else { return false; }
                return true;
            }
            catch
            { return false; }
        }
        # endregion

        # region KDDN-13 -TUNGVT
        public void PC1_BIEU16_IN(string p_ma_dviqly, Int16 p_thang, Int16 p_nam, string p_stt, string p_maso, string p_danhmuc, Int16 p_sltbc, Decimal p_dg, string p_ghichu)
        {
            String SQLERR = "";
            try
            {
                CMIS2.DB.PC1_BIEU16_IN(p_ma_dviqly, p_thang, p_nam, p_stt, p_maso, p_danhmuc, p_sltbc, p_dg,p_ghichu);
            }
            catch (Exception ex)
            {
                return;
            }

        }

        public void PC1_BIEU16_UP(string p_ma_dviqly, Int16 p_thang, Int16 p_nam)
        {
            String SQLERR = "";
            try
            {
                CMIS2.DB.PC1_BIEU16_UP(p_ma_dviqly, p_thang, p_nam);
            }
            catch (Exception ex)
            {
                return;
            }

        }

        public void PC1_BIEU16_DEL(string p_ma_dviqly, Int16 p_thang, Int16 p_nam)
        {
            String SQLERR = "";
            try
            {
                CMIS2.DB.PC1_BIEU16_DEL(p_ma_dviqly, p_thang, p_nam);
            }
            catch (Exception ex)
            {
                return;
            }

        }

        public DataSet select_BCKD16(string strTEN_DVIQLY, string strTEN_CTREN, string strMadviqly, Int16 strThang, Int16 strNam)
        {
            try
            {
                var a = obj_PC1_BCKD16_Controller.select_PC1_BCKD16(strMadviqly, strThang, strNam);
                if (a == null)
                {
                    return null;
                }
                //else
                //{
                //    DataTable dt = Utility.LINQToDataTable(a);
                //    dt.TableName = "IN_BCKD";
                //    DataSet ds = new DataSet();
                //    ds.Tables.Add(dt);
                //    return ds;
                //}

                var BCKD_IN = from p in a
                              select new
                              {
                                  p.DANH_MUC,
                                  p.MA_SO,
                                  p.SL_TBC,
                                  p.SL_LK,
                                  p.DG_TBC,
                                  p.DG_LK,
                                  p.THANG,
                                  p.NAM,
                                  p.MA_DVIQLY,
                                  p.STT,
                                  p.GHI_CHU,
                                  TEN_DVIQLY = " ",
                                  TEN_CTREN = " ",
                              };

                if (BCKD_IN != null && BCKD_IN.Count() > 0)
                {
                    DataTable dt = Utility.LINQToDataTable(BCKD_IN);
                    dt.TableName = "IN_BCKD";
                    foreach (DataRow dr in dt.Rows)
                    {
                        dr["TEN_DVIQLY"] = strTEN_DVIQLY;
                        dr["TEN_CTREN"] = strTEN_CTREN;
                    }
                    dt.AcceptChanges();
                    DataSet ds = new DataSet();
                    ds.Tables.Add(dt);
                    return ds;
                }
                else
                {
                    return null;
                }
            }
            catch
            {
                return null;
            }
        }
        #endregion

        # region KDDN-4A -TUNGVT
        public void PC1_BIEU4A_IN(string p_ma_dviqly, Int16 p_thang, Int16 p_nam, string p_stt, string p_danhmuc, string p_maso, Decimal p_cu1_dk, Decimal p_dt1_dk, Decimal p_cu3_dk, Decimal p_dt3_dk, Decimal p_cu1_m, Decimal p_dt1_m, Decimal p_cu3_m, Decimal p_dt3_m, Decimal p_cu1_t, Decimal p_dt1_t, Decimal p_cu3_t, Decimal p_dt3_t, string p_ghi_chu)
        {
            String SQLERR = "";
            try
            {
                CMIS2.DB.PC1_BIEU4A_IN(p_ma_dviqly, p_thang, p_nam, p_stt, p_danhmuc, p_maso, p_cu1_dk, p_dt1_dk, p_cu3_dk, p_dt3_dk, p_cu1_m, p_dt1_m, p_cu3_m, p_dt3_m, p_cu1_t, p_dt1_t, p_cu3_t, p_dt3_t, p_ghi_chu);
            }
            catch (Exception ex)
            {
                return;
            }

        }

        public void PC1_BIEU4A_UP(string p_ma_dviqly, Int16 p_thang, Int16 p_nam)
        {
            String SQLERR = "";
            try
            {
                CMIS2.DB.PC1_BIEU4A_UP(p_ma_dviqly, p_thang, p_nam);
            }
            catch (Exception ex)
            {
                return;
            }

        }

        public void PC1_BIEU4A_DEL(string p_ma_dviqly, Int16 p_thang, Int16 p_nam)
        {
            String SQLERR = "";
            try
            {
                CMIS2.DB.PC1_BIEU4A_DEL(p_ma_dviqly, p_thang, p_nam);
            }
            catch (Exception ex)
            {
                return;
            }

        }

        public DataSet select_BCKD4A(string strTEN_DVIQLY, string strTEN_CTREN, string strMadviqly, Int16 strThang, Int16 strNam)
        {
            try
            {
                var a = obj_PC1_BCKD_4A_Controller.select_PC1_BCKD4A(strMadviqly, strThang, strNam);
                if (a == null)
                {
                    return null;
                }
                //else
                //{
                //    DataTable dt = Utility.LINQToDataTable(a);
                //    dt.TableName = "IN_BCKD";
                //    DataSet ds = new DataSet();
                //    ds.Tables.Add(dt);
                //    return ds;
                //}

                var BCKD_IN = from p in a
                              select new
                              {
                                  p.DANH_MUC,
                                  p.MA_SO,
                                  p.THANG,
                                  p.NAM,
                                  p.MA_DVIQLY,
                                  p.STT,
                                  p.CU1_DK,
                                  p.DT1_DK,                                  
                                  p.CU3_DK,
                                  p.DT3_DK,
                                  p.CU1_M,
                                  p.DT1_M,
                                  p.CU3_M,
                                  p.DT3_M,
                                  p.CU1_T,
                                  p.DT1_T,
                                  p.CU3_T,
                                  p.DT3_T,
                                  p.GHI_CHU,
                                  TEN_DVIQLY = " ",
                                  TEN_CTREN = " ",
                              };

                if (BCKD_IN != null && BCKD_IN.Count() > 0)
                {
                    DataTable dt = Utility.LINQToDataTable(BCKD_IN);
                    dt.TableName = "IN_BCKD";
                    foreach (DataRow dr in dt.Rows)
                    {
                        dr["TEN_DVIQLY"] = strTEN_DVIQLY;
                        dr["TEN_CTREN"] = strTEN_CTREN;
                    }
                    dt.AcceptChanges();
                    DataSet ds = new DataSet();
                    ds.Tables.Add(dt);
                    return ds;
                }
                else
                {
                    return null;
                }
            }
            catch
            {
                return null;
            }
        }

        public DataSet select_BCKD4A_Full_CTY(string strTEN_DVIQLY, string strTEN_CTREN, string strMadviqly, Int16 strThang, Int16 strNam)
        {
            try
            {
                var a = obj_PC1_BCKD_4A_Controller.select_PC1_BCKD4A(strMadviqly, strThang, strNam);
                if (a == null)
                {
                    return null;
                }
                
                var b = obj_PC1_BCKD_4A_Controller.select_PC1_BCKD4A_411(strMadviqly, strThang, strNam);
                if (b == null)
                    {
                        return null;
                    }

                var cty = from p in a
                              select new
                              {
                                  p.DANH_MUC,
                                  p.MA_SO,
                                  p.THANG,
                                  p.NAM,
                                  p.MA_DVIQLY,
                                  p.STT,
                                  p.CU1_DK,
                                  p.DT1_DK,
                                  p.CU3_DK,
                                  p.DT3_DK,
                                  p.CU1_M,
                                  p.DT1_M,
                                  p.CU3_M,
                                  p.DT3_M,
                                  p.CU1_T,
                                  p.DT1_T,
                                  p.CU3_T,
                                  p.DT3_T,
                                  p.GHI_CHU,
                                  TEN_DVIQLY = " ",
                                  TEN_CTREN = " ",
                              };

                var dluc411 = from p in b
                          select new
                          {
                              p.DANH_MUC,
                              p.MA_SO,
                              p.THANG,
                              p.NAM,
                              p.MA_DVIQLY,
                              p.STT,
                              p.CU1_DK,
                              p.DT1_DK,
                              p.CU3_DK,
                              p.DT3_DK,
                              p.CU1_M,
                              p.DT1_M,
                              p.CU3_M,
                              p.DT3_M,
                              p.CU1_T,
                              p.DT1_T,
                              p.CU3_T,
                              p.DT3_T,
                              p.GHI_CHU,
                              TEN_DVIQLY = " ",
                              TEN_CTREN = " ",
                          };

                
                DataTable dtCty;
                if (cty != null && cty.Count() > 0)
                {
                    dtCty = Utility.LINQToDataTable(cty);
                    dtCty.TableName = "CTY";
                    foreach (DataRow dr in dtCty.Rows)
                    {
                        dr["TEN_DVIQLY"] = strTEN_DVIQLY;
                        dr["TEN_CTREN"] = strTEN_CTREN;
                    }
                    dtCty.AcceptChanges();
                    //DataSet ds = new DataSet();
                    //ds.Tables.Add(dt);
                    //return ds;
                }
                else
                {
                    return null;
                }

                DataTable dtDluc411;
                if (dluc411 != null && dluc411.Count() > 0)
                {
                    dtDluc411 = Utility.LINQToDataTable(dluc411);
                    dtDluc411.TableName = "DLUC411";
                    int i = 1;
                    foreach (DataRow dr in dtDluc411.Rows)
                    {
                        dr["STT"] = i;
                        i = i + 1;
                        dr["TEN_DVIQLY"] = strTEN_DVIQLY;
                        dr["TEN_CTREN"] = strTEN_CTREN;
                    }
                    dtDluc411.AcceptChanges();
                }
                else
                {
                    return null;
                }

                if (dtCty != null)
                {
                    if (dtDluc411 != null)
                    {
                        foreach (DataRow dr in dtDluc411.Rows)
                        {
                            dtCty.ImportRow(dr);
                        }
                        dtCty.AcceptChanges();                        
                    }                   
                }

                if (dtCty != null && dtCty.Rows.Count > 0)
                {
                    DataSet ds = new DataSet();
                    ds.Tables.Add(dtCty);
                    return ds;
                }
                else return null;
            }
            catch
            {
                return null;
            }
        }
        #endregion

        # region KDDN-4B -TUNGVT
        public void PC1_BIEU4B_IN(string p_ma_dviqly, Int16 p_thang, Int16 p_nam, string p_stt, string p_danhmuc, string p_maso, Decimal p_BDA_DK, Decimal p_KHG1_DK, Decimal p_TL1_DK, Decimal p_TONG_DK, Decimal p_CT_DK, Decimal p_HT_DK, Decimal p_KHG2_DK, Decimal p_TL2_DK, Decimal p_BDA_M, Decimal p_CT_M, Decimal p_HT_M, Decimal p_BDA_T, Decimal p_CT_T, Decimal p_HT_T, string p_ghi_chu)
        {
            String SQLERR = "";
            try
            {
                CMIS2.DB.PC1_BIEU4B_IN(p_ma_dviqly, p_thang, p_nam, p_stt, p_danhmuc, p_maso, p_BDA_DK,  p_KHG1_DK,  p_TL1_DK,  p_TONG_DK,  p_CT_DK,  p_HT_DK,  p_KHG2_DK,  p_TL2_DK,  p_BDA_M,  p_CT_M,  p_HT_M,  p_BDA_T,  p_CT_T,  p_HT_T,  p_ghi_chu);
            }
            catch (Exception ex)
            {
                return;
            }

        }

        public void PC1_BIEU4B_UP(string p_ma_dviqly, Int16 p_thang, Int16 p_nam)
        {
            String SQLERR = "";
            try
            {
                CMIS2.DB.PC1_BIEU4B_UP(p_ma_dviqly, p_thang, p_nam);
            }
            catch (Exception ex)
            {
                return;
            }

        }

        public void PC1_BIEU4B_DEL(string p_ma_dviqly, Int16 p_thang, Int16 p_nam)
        {
            String SQLERR = "";
            try
            {
                CMIS2.DB.PC1_BIEU4B_DEL(p_ma_dviqly, p_thang, p_nam);
            }
            catch (Exception ex)
            {
                return;
            }

        }

        public DataSet select_BCKD4B(string strTEN_DVIQLY, string strTEN_CTREN, string strMadviqly, Int16 strThang, Int16 strNam)
        {
            try
            {
                var a = obj_PC1_BCKD_4B_Controller.select_PC1_BCKD4B(strMadviqly, strThang, strNam);
                if (a == null)
                {
                    return null;
                }
                //else
                //{
                //    DataTable dt = Utility.LINQToDataTable(a);
                //    dt.TableName = "IN_BCKD";
                //    DataSet ds = new DataSet();
                //    ds.Tables.Add(dt);
                //    return ds;
                //}

                var BCKD_IN = from p in a
                              select new
                              {
                                  p.DANH_MUC,
                                  p.MA_SO,
                                  p.THANG,
                                  p.NAM,
                                  p.MA_DVIQLY,
                                  p.STT,
                                  p.BDA_DK, 
                                  p.KHG1_DK, 
                                  p.TL1_DK, 
                                  p.TONG_DK, 
                                  p.CT_DK, 
                                  p.HT_DK, 
                                  p.KHG2_DK, 
                                  p.TL2_DK, 
                                  p.BDA_M, 
                                  p.CT_M, 
                                  p.HT_M, 
                                  p.BDA_T, 
                                  p.CT_T, 
                                  p.HT_T,
                                  p.GHI_CHU,
                                  TEN_DVIQLY = " ",
                                  TEN_CTREN = " ",
                              };

                if (BCKD_IN != null && BCKD_IN.Count() > 0)
                {
                    DataTable dt = Utility.LINQToDataTable(BCKD_IN);
                    dt.TableName = "IN_BCKD";
                    foreach (DataRow dr in dt.Rows)
                    {
                        dr["TEN_DVIQLY"] = strTEN_DVIQLY;
                        dr["TEN_CTREN"] = strTEN_CTREN;
                    }
                    dt.AcceptChanges();
                    DataSet ds = new DataSet();
                    ds.Tables.Add(dt);
                    return ds;
                }
                else
                {
                    return null;
                }
            }
            catch
            {
                return null;
            }
        }

        public DataSet select_BCKD4B_Full_CTY(string strTEN_DVIQLY, string strTEN_CTREN, string strMadviqly, Int16 strThang, Int16 strNam)
        {
            try
            {
                var a = obj_PC1_BCKD_4B_Controller.select_PC1_BCKD4B(strMadviqly, strThang, strNam);
                if (a == null)
                {
                    return null;
                }

                var b = obj_PC1_BCKD_4B_Controller.select_PC1_BCKD4B_411(strMadviqly, strThang, strNam);
                if (b == null)
                {
                    return null;
                }

                var cty = from p in a
                          select new
                          {
                              p.DANH_MUC,
                              p.MA_SO,
                              p.THANG,
                              p.NAM,
                              p.MA_DVIQLY,
                              p.STT,
                              p.BDA_DK,
                              p.KHG1_DK,
                              p.TL1_DK,
                              p.TONG_DK,
                              p.CT_DK,
                              p.HT_DK,
                              p.KHG2_DK,
                              p.TL2_DK,
                              p.BDA_M,
                              p.CT_M,
                              p.HT_M,
                              p.BDA_T,
                              p.CT_T,
                              p.HT_T,
                              p.GHI_CHU,
                              TEN_DVIQLY = " ",
                              TEN_CTREN = " ",
                          };

                var dluc411 = from p in b
                              select new
                              {
                                  p.DANH_MUC,
                                  p.MA_SO,
                                  p.THANG,
                                  p.NAM,
                                  p.MA_DVIQLY,
                                  p.STT,
                                  p.BDA_DK,
                                  p.KHG1_DK,
                                  p.TL1_DK,
                                  p.TONG_DK,
                                  p.CT_DK,
                                  p.HT_DK,
                                  p.KHG2_DK,
                                  p.TL2_DK,
                                  p.BDA_M,
                                  p.CT_M,
                                  p.HT_M,
                                  p.BDA_T,
                                  p.CT_T,
                                  p.HT_T,
                                  p.GHI_CHU,
                                  TEN_DVIQLY = " ",
                                  TEN_CTREN = " ",
                              };


                DataTable dtCty;
                if (cty != null && cty.Count() > 0)
                {
                    dtCty = Utility.LINQToDataTable(cty);
                    dtCty.TableName = "CTY";
                    foreach (DataRow dr in dtCty.Rows)
                    {
                        dr["TEN_DVIQLY"] = strTEN_DVIQLY;
                        dr["TEN_CTREN"] = strTEN_CTREN;
                    }
                    dtCty.AcceptChanges();
                    //DataSet ds = new DataSet();
                    //ds.Tables.Add(dt);
                    //return ds;
                }
                else
                {
                    return null;
                }

                DataTable dtDluc411;
                if (dluc411 != null && dluc411.Count() > 0)
                {
                    dtDluc411 = Utility.LINQToDataTable(dluc411);
                    dtDluc411.TableName = "DLUC411";
                    int i = 1;
                    foreach (DataRow dr in dtDluc411.Rows)
                    {
                        dr["STT"] = i;
                        i = i + 1;
                        dr["TEN_DVIQLY"] = strTEN_DVIQLY;
                        dr["TEN_CTREN"] = strTEN_CTREN;
                    }
                    dtDluc411.AcceptChanges();
                }
                else
                {
                    return null;
                }

                if (dtCty != null)
                {
                    if (dtDluc411 != null)
                    {
                        foreach (DataRow dr in dtDluc411.Rows)
                        {
                            dtCty.ImportRow(dr);
                        }
                        dtCty.AcceptChanges();
                    }
                }

                if (dtCty != null && dtCty.Rows.Count > 0)
                {
                    DataSet ds = new DataSet();
                    ds.Tables.Add(dtCty);
                    return ds;
                }
                else return null;
            }
            catch
            {
                return null;
            }
        }
        #endregion

        # region KDDN-5A -TUNGVT
        public void PC1_BIEU5A_IN(string p_ma_dviqly, Int16 p_thang, Int16 p_nam, string p_stt, string p_danhmuc, string p_maso, Decimal p_DAU_KY, Decimal p_TANG, Decimal p_GIAM, Decimal p_LUY_KE)
        {
            String SQLERR = "";
            try
            {
                CMIS2.DB.PC1_BIEU5A_IN(p_ma_dviqly, p_thang, p_nam, p_stt, p_danhmuc, p_maso, p_DAU_KY, p_TANG, p_GIAM, p_LUY_KE);
            }
            catch (Exception ex)
            {
                return;
            }

        }

        public void PC1_BIEU5A_UP(string p_ma_dviqly, Int16 p_thang, Int16 p_nam)
        {
            String SQLERR = "";
            try
            {
                CMIS2.DB.PC1_BIEU5A_UP(p_ma_dviqly, p_thang, p_nam);
            }
            catch (Exception ex)
            {
                return;
            }

        }

        public void PC1_BIEU5A_DEL(string p_ma_dviqly, Int16 p_thang, Int16 p_nam)
        {
            String SQLERR = "";
            try
            {
                CMIS2.DB.PC1_BIEU5A_DEL(p_ma_dviqly, p_thang, p_nam);
            }
            catch (Exception ex)
            {
                return;
            }

        }

        public DataSet select_BCKD5A(string strTEN_DVIQLY, string strTEN_CTREN, string strMadviqly, Int16 strThang, Int16 strNam)
        {
            try
            {
                var a = obj_PC1_BCKD_5A_Controller.select_PC1_BCKD5A(strMadviqly, strThang, strNam);
                if (a == null)
                {
                    return null;
                }
                //else
                //{
                //    DataTable dt = Utility.LINQToDataTable(a);
                //    dt.TableName = "IN_BCKD";
                //    DataSet ds = new DataSet();
                //    ds.Tables.Add(dt);
                //    return ds;
                //}

                var BCKD_IN = from p in a
                              select new
                              {
                                  p.DANH_MUC,
                                  p.MA_SO,
                                  p.THANG,
                                  p.NAM,
                                  p.MA_DVIQLY,
                                  p.STT,
                                  p.DAU_KY,
                                  p.TANG,
                                  p.GIAM,
                                  p.LUY_KE,                                  
                                  TEN_DVIQLY = " ",
                                  TEN_CTREN = " ",
                              };

                if (BCKD_IN != null && BCKD_IN.Count() > 0)
                {
                    DataTable dt = Utility.LINQToDataTable(BCKD_IN);
                    dt.TableName = "IN_BCKD";
                    foreach (DataRow dr in dt.Rows)
                    {
                        dr["TEN_DVIQLY"] = strTEN_DVIQLY;
                        dr["TEN_CTREN"] = strTEN_CTREN;
                    }
                    dt.AcceptChanges();
                    DataSet ds = new DataSet();
                    ds.Tables.Add(dt);
                    return ds;
                }
                else
                {
                    return null;
                }
            }
            catch
            {
                return null;
            }
        }
        
        #endregion

        # region KDDN-5B -TUNGVT
        public void PC1_BIEU5B_IN(string p_ma_dviqly, Int16 p_thang, Int16 p_nam, string p_stt, string p_danhmuc, string p_maso, Decimal p_PHAT_SINH, Decimal p_LUY_KE, String p_GHI_CHU)
        {
            String SQLERR = "";
            try
            {
                CMIS2.DB.PC1_BIEU5B_IN(p_ma_dviqly, p_thang, p_nam, p_stt, p_danhmuc, p_maso, p_PHAT_SINH, p_LUY_KE, p_GHI_CHU);
            }
            catch (Exception ex)
            {
                return;
            }

        }

        public void PC1_BIEU5B_UP(string p_ma_dviqly, Int16 p_thang, Int16 p_nam)
        {
            String SQLERR = "";
            try
            {
                CMIS2.DB.PC1_BIEU5B_UP(p_ma_dviqly, p_thang, p_nam);
            }
            catch (Exception ex)
            {
                return;
            }

        }

        public void PC1_BIEU5B_DEL(string p_ma_dviqly, Int16 p_thang, Int16 p_nam)
        {
            String SQLERR = "";
            try
            {
                CMIS2.DB.PC1_BIEU5B_DEL(p_ma_dviqly, p_thang, p_nam);
            }
            catch (Exception ex)
            {
                return;
            }

        }

        public DataSet select_BCKD5B(string strTEN_DVIQLY, string strTEN_CTREN, string strMadviqly, Int16 strThang, Int16 strNam)
        {
            try
            {
                var a = obj_PC1_BCKD_5B_Controller.select_PC1_BCKD5B(strMadviqly, strThang, strNam);
                if (a == null)
                {
                    return null;
                }
                //else
                //{
                //    DataTable dt = Utility.LINQToDataTable(a);
                //    dt.TableName = "IN_BCKD";
                //    DataSet ds = new DataSet();
                //    ds.Tables.Add(dt);
                //    return ds;
                //}

                var BCKD_IN = from p in a
                              select new
                              {
                                  p.DANH_MUC,
                                  p.MA_SO,
                                  p.THANG,
                                  p.NAM,
                                  p.MA_DVIQLY,
                                  p.STT,
                                  p.PHAT_SINH,
                                  p.LUY_KE,
                                  p.GHI_CHU,                                  
                                  TEN_DVIQLY = " ",
                                  TEN_CTREN = " ",
                              };

                if (BCKD_IN != null && BCKD_IN.Count() > 0)
                {
                    DataTable dt = Utility.LINQToDataTable(BCKD_IN);
                    dt.TableName = "IN_BCKD";
                    foreach (DataRow dr in dt.Rows)
                    {
                        dr["TEN_DVIQLY"] = strTEN_DVIQLY;
                        dr["TEN_CTREN"] = strTEN_CTREN;
                    }
                    dt.AcceptChanges();
                    DataSet ds = new DataSet();
                    ds.Tables.Add(dt);
                    return ds;
                }
                else
                {
                    return null;
                }
            }
            catch
            {
                return null;
            }
        }

        #endregion

        #region NGC - BIEU01 - TUNGVT

        public void NGE_BIEU01(string p_ma_dviqly, Int16 p_thang, Int16 p_nam)
        {
            String SQLERR = "";
            try
            {
                CMIS2.DB.Nge_bieu01(p_ma_dviqly, p_thang, p_nam);
            }
            catch (Exception ex)
            {
                return;
            }

        }

        public void NGE_UPDATE01(Decimal p_dientp, Decimal p_tiendien, Decimal p_tiencspk, Decimal p_tiendienthue, Decimal p_tiencspkthue, Int16 p_nam, Int16 p_thang, String p_ma_dviqly, String p_ma_dviqly1)
        {
            String SQLERR = "";
            try
            {
                CMIS2.DB.Nge_update01(p_dientp, p_tiendien, p_tiencspk, p_tiendienthue, p_tiencspkthue, p_nam, p_thang, p_ma_dviqly, p_ma_dviqly1);
            }
            catch (Exception ex)
            {
                return;
            }

        }

        public DataSet select_NGCBIEU01(string strTEN_DVIQLY, string strTEN_CTREN, string strMadviqly, Int16 strThang, Int16 strNam)
        {
            try
            {
                var a = obj_PC1_NGC_BIEU01_Controller.select_PC1_NGE_BIEU01(strMadviqly, strThang, strNam);
                if (a == null)
                {
                    return null;
                }
                //else
                //{
                //    DataTable dt = Utility.LINQToDataTable(a);
                //    dt.TableName = "IN_BCKD";
                //    DataSet ds = new DataSet();
                //    ds.Tables.Add(dt);
                //    return ds;
                //}

                var BCKD_IN = from p in a
                              select new
                              {
                                  p.MA_DVIQLY, 
                                  p.TEN_DONVI, 
                                  p.THANG, 
                                  p.NAM, 
                                  p.DIEN_TP, 
                                  p.DOANHTHU_TONG, 
                                  p.TIEN_DIEN, 
                                  p.CSPK, 
                                  p.GIA_BQ, 
                                  p.DOANHTHUTHUE_TONG, 
                                  p.TIENTHUE_DIEN, 
                                  p.CSPKTHUE, 
                                  p.TONG_DOANH_THU, 
                                  p.DIEN_TP_LK, 
                                  p.DOANHTHU_TONG_LK, 
                                  p.TIEN_DIEN_LK, 
                                  p.CSPK_LK, 
                                  p.GIA_BQ_LK, 
                                  p.DOANHTHUTHUE_TONG_LK, 
                                  p.TIENTHUE_DIEN_LK, 
                                  p.CSPKTHUE_LK, 
                                  p.TONG_DOANH_THU_LK,
                                  TEN_DVIQLY = " ",
                                  TEN_CTREN = " ",
                              };

                if (BCKD_IN != null && BCKD_IN.Count() > 0)
                {
                    DataTable dt = Utility.LINQToDataTable(BCKD_IN);
                    dt.TableName = "IN_BCKD";
                    foreach (DataRow dr in dt.Rows)
                    {
                        dr["TEN_DVIQLY"] = strTEN_DVIQLY;
                        dr["TEN_CTREN"] = strTEN_CTREN;
                    }
                    dt.AcceptChanges();
                    DataSet ds = new DataSet();
                    ds.Tables.Add(dt);
                    return ds;
                }
                else
                {
                    return null;
                }
            }
            catch
            {
                return null;
            }
        }
        #endregion

        #region NGC - BIEU02 - TUNGVT

        public void NGE_BIEU02(string p_ma_dviqly, Int16 p_thang, Int16 p_nam)
        {
            String SQLERR = "";
            try
            {
                CMIS2.DB.Nge_bieu02(p_ma_dviqly, p_thang, p_nam);
            }
            catch (Exception ex)
            {
                return;
            }

        }

        public void NGE_UPDATE02(Decimal p_congto, Decimal p_hdcnxd, Decimal p_hdqltd, Decimal p_doituong, Decimal p_daky, Decimal p_phaimuacos, Decimal p_nam, Decimal p_thang, String p_ma_dviqly)
        {
            String SQLERR = "";
            try
            {
                CMIS2.DB.Nge_update02(p_congto, p_hdcnxd, p_hdqltd, p_doituong, p_daky, p_phaimuacos, p_nam, p_thang, p_ma_dviqly);
            }
            catch (Exception ex)
            {
                return;
            }

        }

        public DataSet select_NGCBIEU02(string strTEN_DVIQLY, string strTEN_CTREN, string strMadviqly, Int16 strThang, Int16 strNam)
        {
            try
            {
                var a = obj_PC1_NGC_BIEU02_Controller.select_PC1_NGE_BIEU02(strMadviqly, strThang, strNam);
                if (a == null)
                {
                    return null;
                }
                //else
                //{
                //    DataTable dt = Utility.LINQToDataTable(a);
                //    dt.TableName = "IN_BCKD";
                //    DataSet ds = new DataSet();
                //    ds.Tables.Add(dt);
                //    return ds;
                //}

                var BCKD_IN = from p in a
                              select new
                              {
                                  p.MA_DVIQLY, 
                                  p.TEN_DONVI, 
                                  p.THANG, 
                                  p.NAM, 
                                  p.CONG_TO, 
                                  p.TSOHOPDONG, 
                                  p.HDCNXD, 
                                  p.HDQLTD, 
                                  p.DOITUONGMUA, 
                                  p.DAKY, 
                                  p.PHAIMUACOS,
                                  TEN_DVIQLY = " ",
                                  TEN_CTREN = " ",
                              };

                if (BCKD_IN != null && BCKD_IN.Count() > 0)
                {
                    DataTable dt = Utility.LINQToDataTable(BCKD_IN);
                    dt.TableName = "IN_BCKD";
                    foreach (DataRow dr in dt.Rows)
                    {
                        dr["TEN_DVIQLY"] = strTEN_DVIQLY;
                        dr["TEN_CTREN"] = strTEN_CTREN;
                    }
                    dt.AcceptChanges();
                    DataSet ds = new DataSet();
                    ds.Tables.Add(dt);
                    return ds;
                }
                else
                {
                    return null;
                }
            }
            catch
            {
                return null;
            }
        }
        #endregion

        #region NGC - BIEU03 - TUNGVT

        public void NGE_BIEU03(string p_ma_dviqly, Int16 p_thang, Int16 p_nam)
        {
            String SQLERR = "";
            try
            {
                CMIS2.DB.Nge_bieu03(p_ma_dviqly, p_thang, p_nam);
            }
            catch (Exception ex)
            {
                return;
            }

        } 

        public DataSet select_NGCBIEU03(string strTEN_DVIQLY, string strTEN_CTREN, string strMadviqly, Int16 strThang, Int16 strNam)
        {
            try
            {
                var a = obj_PC1_NGC_BIEU03_Controller.select_PC1_NGE_BIEU03(strMadviqly, strThang, strNam);
                if (a == null)
                {
                    return null;
                }
                //else
                //{
                //    DataTable dt = Utility.LINQToDataTable(a);
                //    dt.TableName = "IN_BCKD";
                //    DataSet ds = new DataSet();
                //    ds.Tables.Add(dt);
                //    return ds;
                //}

                var BCKD_IN = from p in a
                              select new
                              {
                                  p.TPSDDIEN, 
                                  p.MSO, 
                                  p.THANG, 
                                  p.NAM, 
                                  p.TTPHAM, 
                                  p.GIOBT, 
                                  p.GIOTD, 
                                  p.GIOCD, 
                                  p.KTG, 
                                  p.TIEN_DIEN, 
                                  p.TTPHAM_LK, 
                                  p.GIOBT_LK, 
                                  p.GIOCD_LK, 
                                  p.GIOTD_LK, 
                                  p.KTG_LK, 
                                  p.TIEN_DIEN_LK, 
                                  p.MA_DVIQLY,
                                  TEN_DVIQLY = " ",
                                  TEN_CTREN = " ",
                              };

                if (BCKD_IN != null && BCKD_IN.Count() > 0)
                {
                    DataTable dt = Utility.LINQToDataTable(BCKD_IN);
                    dt.TableName = "IN_BCKD";
                    foreach (DataRow dr in dt.Rows)
                    {
                        dr["TEN_DVIQLY"] = strTEN_DVIQLY;
                        dr["TEN_CTREN"] = strTEN_CTREN;
                    }
                    dt.AcceptChanges();
                    DataSet ds = new DataSet();
                    ds.Tables.Add(dt);
                    return ds;
                }
                else
                {
                    return null;
                }
            }
            catch
            {
                return null;
            }
        }
        #endregion

        #region NGC - BIEU04 - TUNGVT

        public void NGE_BIEU04(Int16 p_nam, Int16 p_thang, String p_ma_dviqly)
        {
            String SQLERR = "";
            try
            {
                CMIS2.DB.Nge_bieu04(p_nam, p_thang, p_ma_dviqly);
            }
            catch (Exception ex)
            {
                return;
            }

        } 
        
        public DataSet select_NGCBIEU04(string strTEN_DVIQLY, string strTEN_CTREN, string strMadviqly, Int16 strThang, Int16 strNam)
        {
            try
            {
                var a = obj_PC1_NGC_BIEU04_Controller.select_PC1_NGE_BIEU04(strMadviqly, strThang, strNam);
                if (a == null)
                {
                    return null;
                }
                //else
                //{
                //    DataTable dt = Utility.LINQToDataTable(a);
                //    dt.TableName = "IN_BCKD";
                //    DataSet ds = new DataSet();
                //    ds.Tables.Add(dt);
                //    return ds;
                //}

                var BCKD_IN = from p in a
                              select new
                              {
                                  p.MA_DTGIA, 
                                  p.MUCGIA, 
                                  p.SANLUONG, 
                                  p.TTRONG, 
                                  p.TIEN_DIEN, 
                                  p.SANLUONG_LK, 
                                  p.TITRONG_LK, 
                                  p.TIEN_DIEN_LK, 
                                  p.THANG, 
                                  p.NAM, 
                                  p.MA_DVIQLY,
                                  TEN_DVIQLY = " ",
                                  TEN_CTREN = " ",
                              };

                if (BCKD_IN != null && BCKD_IN.Count() > 0)
                {
                    DataTable dt = Utility.LINQToDataTable(BCKD_IN);
                    dt.TableName = "IN_BCKD";
                    foreach (DataRow dr in dt.Rows)
                    {
                        dr["TEN_DVIQLY"] = strTEN_DVIQLY;
                        dr["TEN_CTREN"] = strTEN_CTREN;
                    }
                    dt.AcceptChanges();
                    DataSet ds = new DataSet();
                    ds.Tables.Add(dt);
                    return ds;
                }
                else
                {
                    return null;
                }
            }
            catch
            {
                return null;
            }
        }
        #endregion

        #region NGC - BIEU05 - TUNGVT

        public void NGE_BIEU05(Int16 p_nam, Int16 p_thang, string p_ma_dviqly)
        {
            String SQLERR = "";
            try
            {
                CMIS2.DB.Nge_bieu05(p_nam, p_thang, p_ma_dviqly);
            }
            catch (Exception ex)
            {
                return;
            }

        }

        public void NGE_UPDATE05( Decimal dunodt, Decimal thutthang, String p_madm, Decimal p_nam, Decimal p_thang, String p_ma_dviqly)
        {
            String SQLERR = "";
            try
            {
                CMIS2.DB.Nge_update05(dunodt, thutthang, p_madm, p_nam, p_thang, p_ma_dviqly);
            }
            catch (Exception ex)
            {
                return;
            }

        }

        public DataSet select_NGCBIEU05(string strTEN_DVIQLY, string strTEN_CTREN, string strMadviqly, Int16 strThang, Int16 strNam)
        {
            try
            {
                var a = obj_PC1_NGC_BIEU05_Controller.select_PC1_NGE_BIEU05(strMadviqly, strThang, strNam);
                if (a == null)
                {
                    return null;
                }
                //else
                //{
                //    DataTable dt = Utility.LINQToDataTable(a);
                //    dt.TableName = "IN_BCKD";
                //    DataSet ds = new DataSet();
                //    ds.Tables.Add(dt);
                //    return ds;
                //}

                var BCKD_IN = from p in a
                              select new
                              {
                                  p.KHOANMUC, 
                                  p.SODU_DT, 
                                  p.PHATSINH, 
                                  p.SO_THUDUOC, 
                                  p.SODUCT, 
                                  p.THANG, 
                                  p.NAM, 
                                  p.MA_DVIQLY, 
                                  p.MADM,
                                  TEN_DVIQLY = " ",
                                  TEN_CTREN = " ",
                              };

                if (BCKD_IN != null && BCKD_IN.Count() > 0)
                {
                    DataTable dt = Utility.LINQToDataTable(BCKD_IN);
                    dt.TableName = "IN_BCKD";
                    foreach (DataRow dr in dt.Rows)
                    {
                        dr["TEN_DVIQLY"] = strTEN_DVIQLY;
                        dr["TEN_CTREN"] = strTEN_CTREN;
                    }
                    dt.AcceptChanges();
                    DataSet ds = new DataSet();
                    ds.Tables.Add(dt);
                    return ds;
                }
                else
                {
                    return null;
                }
            }
            catch
            {
                return null;
            }
        }
        #endregion

        #region KDDN - BIA BAOCAO - TUNGVT

        public DataSet select_PC1_BIABC(string strMadviqly)
        {
            try
            {
                var a = obj_PC1_BIABC_Controller.select_PC1_BIABC(strMadviqly);
                if (a == null)
                {
                    return null;
                }               

                var BCKD_IN = from p in a
                              select new
                              {
                                  p.MA_DVIQLY,
                                  p.NOI_DUNG,
                                  p.SO_BCAO,                                 
                              };

                if (BCKD_IN != null && BCKD_IN.Count() > 0)
                {
                    DataTable dt = Utility.LINQToDataTable(BCKD_IN);
                    dt.TableName = "IN_BCKD";
                    //foreach (DataRow dr in dt.Rows)
                    //{
                    //    dr["TEN_DVIQLY"] = strTEN_DVIQLY;
                    //    dr["TEN_CTREN"] = strTEN_CTREN;
                    //}
                    //dt.AcceptChanges();
                    DataSet ds = new DataSet();
                    ds.Tables.Add(dt);
                    return ds;
                }
                else
                {
                    return null;
                }
            }
            catch
            {
                return null;
            }
        }

        public bool insert_PC1_BIABC(string strMadviqly, string strNoidung, string strSobcao)
        {
            try
            {
                //this.mapEntityToInfo(Entity);
                if (obj_PC1_BIABC_Controller == null)
                {
                    obj_PC1_BIABC_Controller = new cls_PC1_BIABC_Controller();
                }
                return obj_PC1_BIABC_Controller.insert_PC1_BIABC(strMadviqly,strNoidung,strSobcao);
            }
            catch (Exception ex)
            {
                //strErr = ex.Message;
                return false;
            }
        }

        public bool update_PC1_BIABC(string strMadviqly, string strNoidung, string strSobcao)
        {
            try
            {
                //this.mapEntityToInfo(Entity);
                if (obj_PC1_BIABC_Controller == null)
                {
                    obj_PC1_BIABC_Controller = new cls_PC1_BIABC_Controller();
                }
                return this.obj_PC1_BIABC_Controller.update_PC1_BIABC(strMadviqly, strNoidung, strSobcao);
            }
            catch (Exception ex)
            {
                //strErr = ex.Message;
                return false;
            }

        }

        #endregion


        #region KDDN-11/12  -Tungnd
        public DataSet select_PC1_BCKD17(String strMa_dviqly,int p_thang,int p_nam)
        {
            try
            {
                //this.mapEntityToInfo(Entity);
                var q = from p in obj_pc1_bieu17_Controller.select_PC1_BCKD17(strMa_dviqly,p_thang,p_nam)
                        select new
                        {
                            p.STT,
                            p.DOI_TUONG,
                            p.MA_SO,
                            p.TS_KH,
                            p.SL_BBKT,
                            p.SL_VPSDD_HD,
                            p.SL_VPHC,
                            p.KQ_HH_TS,
                            p.KQ_HH_CT,
                            p.KQ_HH_TUTI,
                            p.KQ_HH_MD,
                            p.KQ_HH_HSN,
                            p.KQ_HH_SK,
                            p.KQ_VP_TCD_TS,
                            p.KQ_VP_TCD_CM,
                            p.KQ_VP_TCD_XPCT,
                            p.KQ_VP_TCD_XPMD,
                            p.KQ_VP_TCD_HTK,
                            p.KQ_VP_CSGCD,
                            p.KQ_VP_GD_TS,
                            p.KQ_VP_GD_SMD,
                            p.KQ_VP_GD_AGS,
                            p.KQ_VP_VPK,
                        };
                if (q != null && q.Count() > 0)
                {
                    DataTable dt = Utility.LINQToDataTable(q);
                    dt.TableName = "PC1_BCKD17";
                    DataSet ds = new DataSet();
                    ds.Tables.Add(dt);
                    return ds;
                }
                else return null;
            }
            catch
            {
                return null;
            }
        }
        public DataSet KHOITAO_BIEU17(Int16 iNam, Int16 iThang, System.String strMaDviqly)
        {
            String strErr = "";
            DataSet ds = new DataSet();
            try
            {
                //========     UPDATE BIEU 17  =============
                CMIS2.DB.KHOITAO_PC1_BIEU17(iNam,iThang, strMaDviqly);
                return ds;

                //return 1;
            }
            catch (Exception ex)
            { return null; }
            finally
            {
            }
        }
        public DataSet INBIEU(System.String strMaDviqly, Int16 iNam, Int16 iThang, Int16 bieu)
        {
            String strErr = "";
            DataSet ds = new DataSet();
            try
            {
                //========     UPDATE BIEU 17  =============
                CMIS2.DB.INBIEU(strMaDviqly, iNam, iThang,bieu, out ds);
                if (ds != null)
                {
                    if (strErr != null && ds != null && ds.Tables.Count > 0)
                    {
                        //DataTable dt = Utility.LINQToDataTable(ds);
                        if (bieu == 17)
                        {
                            ds.Tables[0].TableName = "PC1_BCKD17";
                        }
                        if (bieu == 18)
                        {
                            ds.Tables[0].TableName = "PC1_BCKD18";
                        }
                        //dt.TableName = "PA_GIAY_GIAO_NVU_IN";
                        //DataSet ds1 = new DataSet();
                        //ds.Tables.Add(dt);
                        return ds;
                    }
                    return ds;
                }
                else
                {
                    return null;
                }
                //return 1;
            }
            catch (Exception ex)
            { return null; }
            finally
            {
            }
        }
        public DataSet Chon_cty_dienluc(Int16 iNam, Int16 iThang, System.String strMaDviqly,Int16 p_bieu)
        {
            String strErr = "";
            DataSet ds = new DataSet();
            try
            {
                //========     UPDATE BIEU 17  =============
                CMIS2.DB.Chon_cty_dienluc(iNam, iThang, strMaDviqly, p_bieu);
                return ds;

                //return 1;
            }
            catch (Exception ex)
            { return null; }
            finally
            {
            }
        }
        public DataSet UPDATE_BIEU17(Int16 iNam, Int16 iThang, System.String strMaDviqly, System.String ma_so, Int64 TSKH, Int64 SL_BBKT, Int64 SL_VPHC, Int64 KQ_HH_CT, Int64 KQ_HH_TUTI, Int64 KQ_HH_MD, Int64 KQ_HH_HSN, Int64 KQ_HH_SK, Int64 KQ_VP_TCD_CM, Int64 KQ_VP_TCD_XPCT, Int64 KQ_VP_TCD_XPMD, Int64 KQ_VP_TCD_HTK, Int64 KQ_VP_CSGCD, Int64 KQ_VP_GD_SMD, Int64 KQ_VP_GD_AGS, Int64 KQ_VP_VPK)
        {
            String strErr = "";
            DataSet ds = new DataSet();
            try
            {
                //========     UPDATE BIEU 17  =============
                CMIS2.DB.UPDATE_PC1_BIEU17(iNam, iThang, strMaDviqly, ma_so,TSKH, SL_BBKT, SL_VPHC, KQ_HH_CT, KQ_HH_TUTI, KQ_HH_MD, KQ_HH_HSN, KQ_HH_SK, KQ_VP_TCD_CM, KQ_VP_TCD_XPCT, KQ_VP_TCD_XPMD, KQ_VP_TCD_HTK, KQ_VP_CSGCD, KQ_VP_GD_SMD, KQ_VP_GD_AGS, KQ_VP_VPK, out strErr);
                //if (strErr == "")
                //{
                //    SING "Tổng hợp biểu 02 thành công.";
                //}
                //else
                //{
                //    dr["LOG"] = strErr;
                //}
                //dt.Rows.InsertAt(dr, 0);


                return ds;

                //return 1;
            }
            catch (Exception ex)
            { return null; }
            finally
            {
            }
        }
        #endregion

        #region KDDN-12 TUNGND
        public DataSet select_PC1_BCKD18(String strMa_dviqly, int p_thang, int p_nam)
        {
            try
            {
                //this.mapEntityToInfo(Entity);
                var q = from p in obj_pc1_bieu18_Controller.select_PC1_BCKD18(strMa_dviqly, p_thang, p_nam)
                        select new
                        {
                            p.STT,
                            p.DOI_TUONG,
                            p.MA_SO,
                            p.TSV_DXLX,
                            p.TSV_DXL,
                            p.TSV_CSCT,
                            p.DN_TOTH,
                            p.DN_TRTH,
                            p.DN_THHO,
                            p.DN_BOTH,
                            p.ST_TOTH,
                            p.ST_TRTH,
                            p.ST_THHO,
                            p.ST_BOTH,
                            p.ST_PH,
                            p.ST_THKH,
                        };
                if (q != null && q.Count() > 0)
                {
                    DataTable dt = Utility.LINQToDataTable(q);
                    dt.TableName = "PC1_BCKD18";
                    DataSet ds = new DataSet();
                    ds.Tables.Add(dt);
                    return ds;
                }
                else return null;
            }
            catch
            {
                return null;
            }
        }
        public DataSet KHOITAO_BIEU18(Int16 iNam, Int16 iThang, System.String strMaDviqly)
        {
            String strErr = "";
            DataSet ds = new DataSet();
            try
            {
                //========     UPDATE BIEU 18  =============
                CMIS2.DB.KHOITAO_PC1_BIEU18(iNam, iThang, strMaDviqly);
                return ds;

                //return 1;
            }
            catch (Exception ex)
            { return null; }
            finally
            {
            }
        }
        public DataSet UPDATE_BIEU18(Int16 iNam, Int16 iThang, System.String strMaDviqly, System.String ma_so, Int64 TSV_DXLX, Int64 TSV_DXL, Int64 TSV_CSCT, Int64 DN_TRTH, Int64 DN_THHO, Int64 DN_BOTH, Int64 ST_TRTH, Int64 ST_THHO, Int64 ST_BOTH, Int64 ST_PH, Int64 ST_THKH)
        {
            String strErr = "";
            DataSet ds = new DataSet();
            try
            {
                //========     UPDATE BIEU 17  =============
                CMIS2.DB.UPDATE_PC1_BIEU18(iNam, iThang, strMaDviqly, ma_so, TSV_DXLX, TSV_DXL, TSV_CSCT, DN_TRTH, DN_THHO, DN_BOTH, ST_TRTH, ST_THHO, ST_BOTH, ST_PH, ST_THKH, out strErr);
                //if (strErr == "")
                //{
                //    SING "Tổng hợp biểu 02 thành công.";
                //}
                //else
                //{
                //    dr["LOG"] = strErr;
                //}
                //dt.Rows.InsertAt(dr, 0);


                return ds;

                //return 1;
            }
            catch (Exception ex)
            { return null; }
            finally
            {
            }
        }
        #endregion

        #region KDDN-00 TUNGND
        public DataSet BCKD00_DANHMUC(String strMa_dviqly, Int16 bieu)
        {
            String strErr = "";
            DataSet ds = new DataSet();
            try
            {
                //========     UPDATE BIEU 00  =============
                CMIS2.DB.BCKD00_DANHMUC(strMa_dviqly, bieu, out ds);
                return ds;

                //return 1;
            }
            catch (Exception ex)
            { return null; }
            finally
            {
            }
        }
        public void INSERT_DM(Int16 P_STT, string P_DVT, string P_DM, string P_MASO, string p_madonvi)
        {

            try
            {
                CMIS2.DB.BCKD00_DM_THEMSUAXOA(1, P_STT, P_DVT, P_DM, P_MASO, p_madonvi);

            }
            catch
            { return; }

        }
        public void UPDATE_DM(Int16 P_STT, string P_DVT, string P_DM, string P_MASO, string p_madonvi)
        {

            try
            {
                CMIS2.DB.BCKD00_DM_THEMSUAXOA(2, P_STT, P_DVT, P_DM, P_MASO, p_madonvi);

            }
            catch
            { return; }

        }
        public void DELETE_DM( Int16 P_STT, string P_DVT, string P_DM, string P_MASO, string p_madonvi)
        {

            try
            {
                CMIS2.DB.BCKD00_DM_THEMSUAXOA(3, P_STT, P_DVT, P_DM, P_MASO,p_madonvi);

            }
            catch
            { return; }

        }
        public DataSet KHOITAO_BIEU00(Int16 iNam, Int16 iThang, System.String strMaDviqly)
        {
            String strErr = "";
            DataSet ds = new DataSet();
            try
            {
                //========     UPDATE BIEU 00  =============
                CMIS2.DB.KHOITAO_PC1_BIEU00(iNam, iThang, strMaDviqly);
                return ds;

                //return 1;
            }
            catch (Exception ex)
            { return null; }
            finally
            {
            }
        }
        public bool DELETE_00(Int16 p_nam, Int16 p_thang, string p_madonvi)
        {

            try
            {
                CMIS2.DB.DELETE_00(p_nam, p_thang, p_madonvi);
                return true;
            }
            catch
            { return false; }

        }
        public void UPDATE00(Int16 p_nam, Int16 p_thang, string p_madonvi)
        {

            try
            {
                CMIS2.DB.UPDATE00(p_nam, p_thang, p_madonvi);

            }
            catch
            { return; }

        }
        public bool Insert_BCKD00(DataSet ds)
        {

            try
            {
                string strMaLoi = "";
                mapinfo_BCKD00(ds.Tables["PC1_BCKD00"]);
                if (obj_pc1_bieu00_Controller.insert_BCKD00())
                {
                    if (obj_NPC_BCKD07_Controller.submitChange(ref strMaLoi))
                    { return true; }
                    else { return false; }
                 }
                return true;
            }
            catch
            { return false; }

        }
        public bool BCKD00(Int16 p_nam, Int16 p_thang, string p_madonvi, Int16 P_STT, string P_DM_NAME, string P_MASO, string P_DONVI_DO, Double P_KH_GIAO, Double P_THANG_TH, Double P_LUYKE_TH, string P_PHANTICH_DANHGIA, string P_YKIEN_KHAC)
        {

            try
            {
                CMIS2.DB.BCKD00(p_nam, p_thang, p_madonvi, P_STT, P_DM_NAME, P_MASO, P_DONVI_DO, P_KH_GIAO, P_THANG_TH, P_LUYKE_TH,P_PHANTICH_DANHGIA, P_YKIEN_KHAC);
                return true;
            }
            catch
            { return false; }

        }
        public void tonghop(Int16 p_nam, Int16 p_thang, string p_madonvi)
        {

            try
            {
                CMIS2.DB.TONGHOP(p_nam, p_thang, p_madonvi);
            }
            //catch
            //{ return; }
            catch (Exception ex)
            {
                MessageBox.Show("Lỗi : " + ex.ToString(), "Thông báo");
                return;
            }

        }
        public DataSet select_PC1_BCKD00(String strMa_dviqly, int p_thang, int p_nam)
        {
            try
            {
                //this.mapEntityToInfo(Entity);
                var q = from p in obj_pc1_bieu00_Controller.select_PC1_BCKD00(strMa_dviqly, p_thang, p_nam)
                        select new
                        {
                            p.MA_DVIQLY,
                            p.STT,
                            p.DANH_MUC,
                            p.MA_SO,
                            p.DVT,
                            p.KH_GIAO,
                            p.THANG_TH,
                            p.LUYKE_TH,
                            p.SOSANH_THKH,
                            p.THANG,
                            p.NAM,
                            p.PHANTICH_DANHGIA,
                            p.YKIEN_KHAC
                        };
                if (q != null && q.Count() > 0)
                {
                    DataTable dt = Utility.LINQToDataTable(q);
                    dt.TableName = "PC1_BCKD00";
                    DataSet ds = new DataSet();
                    ds.Tables.Add(dt);
                    return ds;
                }
                else return null;
            }
            catch
            {
                return null;
            }
        }
        # endregion

        # endregion

        #region NPC_ATM
        public DataSet get_dsKH_thuATM(string strMadvi, string strMaNH, string strMAPTTT, DateTime? pNgaythu_tu, DateTime? pNgaythu_den, int i_ttrang_no)
        {
            try
            {

                return obj_CN_THEODOINO_Controller.get_dsKH_thuATM(strMadvi, strMaNH, strMAPTTT, pNgaythu_tu, pNgaythu_den, i_ttrang_no);
            }
            catch
            { return null; }
        }
        public DataSet get_dsKH_thuATM_TNGAN(string strMadvi, string strMaTNGAN, DateTime? pNgaythu_tu, DateTime? pNgaythu_den)
        {
            try
            {

                return obj_CN_THEODOINO_Controller.get_dsKH_thuATM_TNGAN(strMadvi, strMaTNGAN, pNgaythu_tu, pNgaythu_den);
            }
            catch
            { return null; }
        }
        public DataSet get_DM_NHANG()
        {
            try
            {
                return obj_CN_THEODOINO_Controller.get_DM_NHANG();
            }
            catch { return null; }
        }
        public DataSet get_DM_TNGANVIEN(string strMadvi)
        {
            try
            {
                return obj_CN_THEODOINO_Controller.get_DM_TNGAN(strMadvi);
            }
            catch { return null; }
        }
        public DataSet get_PHTHUC_TTOAN()
        {
            try
            {
                return obj_CN_THEODOINO_Controller.get_PHTHUC_TTOAN();
            }
            catch { return null; }
        }
        public DataSet get_TIMESPAN(string strMadvi)
        {
            try
            {
                return obj_CN_THEODOINO_Controller.get_TIMESPAN(strMadvi);
            }
            catch { return null; }
        }
        public bool chamno_ATM(DataSet ds, DateTime pngaygiao, string strUsername, ref string ERRO)
        {
            try
            {
                long psophieuthu = -1, psobbangiao = -1;
                //long psobbangiao = -1;
                string strManvien, strMaLoi = "";
                long ptongtien = 0;
                long ptongthue = 0;
                string p_tngan = "";
                Int32 icount = 0;
                strManvien = obj_CN_THEODOINO_Controller.get_DM_NVIEN(ds.Tables["DSCHAMNO"].Rows[0]["MA_DVIQLY"].ToString());
                //DataTable dtgiao = new DataTable();
                //dtgiao.Columns.Add("MA_DVIQLY");
                //dtgiao.Columns.Add("LOAI_HDON");
                //dtgiao.Columns.Add("ID_HDON");
                //dtgiao.Columns.Add("SO_TIEN");
                //dtgiao.Columns.Add("TIEN_GTGT");
                //dtgiao.Columns.Add("MA_SOGCS");
                foreach (DataRow dr in ds.Tables["DSCHAMNO"].Rows)
                {

                    p_tngan = obj_CN_THEODOINO_Controller.get_TNVIEN_by_IDHDON(dr["MA_DVIQLY"].ToString(), Convert.ToInt64(dr["ID_HDON"]));
                    if (p_tngan == null || p_tngan.Trim().Length == 0)
                    { ERRO = "Không lấy được mã TNV gia của ID_HDON:" + dr["ID_HDON"].ToString(); return false; }

                    //Them phieu thu, lay psophieuthu
                    mapinfo_CN_PHIEU_THU(dr, p_tngan, strUsername);
                    if (obj_CN_PHIEU_THU_Controller.insert_PhieuThu(ref psophieuthu))
                    {
                        mapinfo_CN_HDON_PHTHU(dr, p_tngan, psophieuthu, strUsername);
                        if (obj_CN_HDON_PHTHU_Controller.insert_CN_HDON_PHTHU())
                        {
                            mapinfo_CN_THEODOINO(dr);
                            if (obj_CN_THEODOINO_Controller.update_chamno_ATM())
                            {
                                mapinfo_NPC_HDON_TKHOAN(dr, strUsername);
                                obj_NPC_HDON_TKHOAN_Controller.update_NPC_HDON_TKHOAN_CHAMNO();

                            }
                            else { return false; }

                        }
                        else
                        { return false; }
                    }
                    else
                    {
                        return false;
                    }
                    //Them vao bang NPC_LOG_CHAMNO
                    mapinfo_NPC_LOG_CHAMNO(dr, strUsername, "0", 1, "INS");
                    obj_NPC_LOG_CHAMNO_Controller.insert_NPC_LOG_CHAMNO(ref ERRO);
                }
                //Dungnt bo ngay 06/05/2013 khong thuc hien cham cho nhung hoa dong chua giao
                //if (icount > 0)//thuc hien giao thu nhung hoa don chua duoc giao
                //{
                //    psobbangiao = obj_CN_BB_GTHU_Controller.GetSequence(ref strMaLoi);
                //    MapInfo_GTHU(dtgiao, ptongtien, ptongthue, strMatngan, strManvien, icount, pngaygiao, psobbangiao);
                //    if (obj_CN_BB_GTHU_Controller.insert_CN_BB_GTHU())
                //    {
                //        if (obj_CN_HDON_GTHU_Controller.INSERT_CN_HDON_GTHU(ref strMaLoi) && obj_CN_THEODOINO_Controller.update_TTHAI_GIAO())
                //        {
                //            if (obj_NPC_BCKD07_Controller.submitChange(ref strMaLoi))
                //            { return true; }
                //            else { return false; }
                //        }
                //        else return false;
                //    }
                //    else { return false; }
                //}
                if (obj_NPC_BCKD07_Controller.submitChange(ref strMaLoi))
                {

                    return true;
                }
                else { ERRO = strMaLoi; return false; }


            }
            catch { return false; }
        }
        public bool update_chamno_atm_ERRO(DataSet ds, string strUsername, ref string ERRO)
        {
            try
            {
                string strMaLoi = "";
                foreach (DataRow dr in ds.Tables["ERRO"].Rows)
                {
                    mapinfo_NPC_HDON_TKHOAN_ERRO(dr);
                    if (!obj_NPC_HDON_TKHOAN_Controller.update_NPC_HDON_TKHOAN_CHAMNO_ERRO())
                    { return false; }
                    mapinfo_NPC_LOG_CHAMNO(dr, strUsername, dr["MA_ERRO"].ToString(), 0, "INS");
                    obj_NPC_LOG_CHAMNO_Controller.insert_NPC_LOG_CHAMNO(ref ERRO);
                }
                if (obj_NPC_BCKD07_Controller.submitChange(ref strMaLoi))
                { return true; }
                else { return false; }
            }
            catch
            {

                return false;
            }
        }
        public bool cancel_chamno_atm(DataSet ds, string strUsername, ref string ERRO)
        {
            try
            {
                long psophieuthu = -1;
                //long psobbangiao = -1;
                string strMadonvi, strloaiHdon = "";
                long pIDHDON = 0;
                Decimal ptien_nop = 0, pthue_nop = 0;

                foreach (DataRow dr in ds.Tables["HUYCHAM"].Rows)
                {
                    strMadonvi = dr["MA_DVIQLY"].ToString();
                    strloaiHdon = dr["LOAI_HDON"].ToString();
                    pIDHDON = Convert.ToInt64(dr["ID_HDON"].ToString());
                    ptien_nop = Convert.ToDecimal(dr["SO_TIEN"].ToString());
                    pthue_nop = Convert.ToDecimal(dr["TIEN_GTGT"].ToString());

                    if (obj_CN_HDON_PHTHU_Controller.delete_CN_HDON_PHTHU_ATM(strMadonvi, strloaiHdon, pIDHDON, ref psophieuthu))
                    {
                        obj_CN_PHIEU_THU_Controller.delete_PhieuThu(strMadonvi, psophieuthu);
                        obj_CN_THEODOINO_Controller.update_chamno_Cancel(strMadonvi, strloaiHdon, pIDHDON, ptien_nop, pthue_nop);
                        mapinfo_NPC_HDON_TKHOAN(dr, strUsername);
                        obj_NPC_HDON_TKHOAN_Controller.update_NPC_HDON_TKHOAN_CHAMNO_CANCEL();
                        mapinfo_NPC_LOG_CHAMNO(dr, strUsername, "0", 0, "CAN");
                        obj_NPC_LOG_CHAMNO_Controller.insert_NPC_LOG_CHAMNO(ref ERRO);
                    }
                    else
                    { return false; }
                }
                if (obj_NPC_BCKD07_Controller.submitChange(ref ERRO))
                { return true; }
                else { return false; }

            }
            catch { return false; }
        }
        public bool Insert_LogChamno(DataSet ds, string strUsername, string strMA_ERRO, short itinhtrang, string strMA_Thaotac, ref string ERRO)
        {
            try
            {
                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    mapinfo_NPC_LOG_CHAMNO(dr, strUsername, strMA_ERRO, itinhtrang, strMA_Thaotac);
                    obj_NPC_LOG_CHAMNO_Controller.insert_NPC_LOG_CHAMNO(ref ERRO);
                }
                if (obj_NPC_BCKD07_Controller.submitChange(ref ERRO))
                { return true; }
                else { return false; }
            }
            catch (Exception ex)
            {
                ERRO = ex.ToString(); return false;
            }
        }
        public string convertDateToShort(string date)
        {
            string thang = date.Substring(0, date.IndexOf(@"/"));
            date = date.Substring(date.IndexOf(@"/") + 1);
            string ngay = date.Substring(0, date.IndexOf(@"/"));
            date = date.Substring(date.IndexOf(@"/") + 1, 4);
            return thang + @"/" + ngay + @"/" + date;
        }
        #endregion

        #region Chamno_Offline
        public DataSet get_dsno(DataSet ds, string strMadvi)
        {
            try
            {

                return obj_CN_THEODOINO_Controller.get_DSNO(ds, strMadvi);
            }
            catch
            { return null; }
        }
        public DataSet get_dsthutien_offline(string strMadvi, string strMatngan, Int16 ithanght, Int16 inamht, DateTime? pNgaythu_tu, DateTime? pNgaythu_den, DateTime? pNgaythu, int Danhsach, int IN_BC, string lanin)
        {
            try
            {

                return obj_CN_THEODOINO_Controller.get_DSTHUTIEN(strMadvi, strMatngan, ithanght, inamht, pNgaythu_tu, pNgaythu_den, pNgaythu, Danhsach, IN_BC, lanin);
            }
            catch
            { return null; }
        }
        public DataSet get_dschamno(string strMadvi, string strMatngan, Int16 ithanght, Int16 inamht, int ilsu, DateTime? pNgaythu_tu, DateTime? pNgaythu_den)
        {
            try
            {

                return obj_CN_THEODOINO_Controller.get_DSCHAMNO_OFFLINE(strMadvi, strMatngan, ithanght, inamht, ilsu, pNgaythu_tu, pNgaythu_den);
            }
            catch
            { return null; }
        }
        public bool chamno_OFFLINE(DataSet ds, string strUsername, Int16 ithanght, Int16 inamht, ref string ERRO)
        {
            try
            {
                long psophieuthu = -1;
                //long psobbangiao = -1;
                string strManvien, strMaLoi = "";
                DataRow[] drselect = ds.Tables["DSNO"].Select("CHON=1");
                foreach (DataRow dr in drselect)
                {
                    //Them phieu thu, lay psophieuthu
                    mapinfo_CN_PHIEU_THU(dr, dr["MA_TNGAN"].ToString(), strUsername);
                    if (obj_CN_PHIEU_THU_Controller.insert_PhieuThu(ref psophieuthu))
                    {
                        mapinfo_CN_HDON_PHTHU(dr, dr["MA_TNGAN"].ToString(), psophieuthu, strUsername);
                        if (obj_CN_HDON_PHTHU_Controller.insert_CN_HDON_PHTHU())
                        {
                            mapinfo_CN_THEODOINO(dr);
                            if (obj_CN_THEODOINO_Controller.update_chamno_ATM())
                            {
                                mapinfo_NPC_CHAMNO_OFFLINE(dr, strUsername, ithanght, inamht);
                                obj_NPC_CHAMNO_OFFLINE_Controller.insert_NPC_CHAMNO_OFFLINE(ref ERRO);
                            }
                            else { return false; }
                        }
                        else
                        { return false; }

                    }
                    else
                    {
                        return false;
                    }

                }
                if (obj_NPC_BCKD07_Controller.submitChange(ref strMaLoi))
                {

                    return true;
                }
                else { ERRO = strMaLoi; return false; }


            }
            catch { return false; }
        }

        #endregion

        #region TRUY_THU

        public DataSet Get_thongtin_khach_hang(string strMa_dviqly, string strMa_ddo)
        {
            try
            {
                DataSet ds = new DataSet();
                ds = obj_TRUY_THU_Controller.Get_thongtin_khach_hang(strMa_dviqly, strMa_ddo);
                return ds;
            }
            catch
            {
                return null;
            }
        }

        public DataSet Get_thongtin_Ban_dien(string strMa_dviqly)
        {
            try
            {
                DataSet ds = new DataSet();
                ds = obj_TRUY_THU_Controller.Get_thongtin_Ban_dien(strMa_dviqly);
                return ds;

            }
            catch
            { return null; }
        }

        public DataSet Get_Sanluong_Cancu_Co(string strMa_ddo, DateTime dtNgaystop)
        {
            try
            {
                DataSet ds = new DataSet();
                ds = obj_TRUY_THU_Controller.Get_Sanluong_Cancu_Co(strMa_ddo, dtNgaystop);
                return ds;

            }
            catch
            {
                return null;
            }
        }

        public DataSet Get_Sanluong_Cancu_Dtu(string strMa_dviqly, string strMa_ddo, DateTime dtNgaystop, int intThangHD, int intNamHD)
        {
            try
            {
                DataSet ds = new DataSet();
                ds = obj_TRUY_THU_Controller.Get_Sanluong_Cancu_Dtu(strMa_dviqly, strMa_ddo, dtNgaystop, intThangHD, intNamHD);
                return ds;

            }
            catch
            {
                return null;
            }
        }

        public string get_chuoigia(string strma_dviqly, string ma_ddo)
        {
            try
            {
                string strout = "";
                strout = obj_NPC_INTOGCS_Controller.get_chuoigia(strma_dviqly, ma_ddo);
                return strout;
            }
            catch
            { return ""; }
        }

        public DataSet GetGia_By_MaDDoBCS(string strma_dviqly, string strma_ddo)
        {
            try
            {
                DataSet ds = new DataSet();
                CMIS2.DB.GetGia_By_MaDDoBCS(strma_dviqly, strma_ddo,out ds);
                return ds;
            }
            catch
            { return null; }
        }

        public string Get_loai_khang(string strMa_dviqly, string strMa_ddo)
        {
            try
            {
                string Loai_khang = "";
                Loai_khang = obj_TRUY_THU_Controller.Get_loai_khang(strMa_dviqly, strMa_ddo);
                return Loai_khang; 
            }
            catch
            {
                return "";
            }
        }

        public DataSet Get_Apgia_SHBT(string strMa_dviqly, string strMa_ddo)
        {
            try
            {
                DataSet ds = new DataSet();
                ds = obj_TRUY_THU_Controller.Get_Apgia_SHBT(strMa_dviqly, strMa_ddo);
                return ds;
            }
            catch
            {
                return null;
            }
        }

        public DataSet Get_ky_GCS(string strMa_dviqly, string strMa_ddo)
        {
            try
            {
                DataSet ds = new DataSet();
                ds = obj_TRUY_THU_Controller.Get_ky_GCS(strMa_dviqly, strMa_ddo);
                return ds;
            }
            catch
            {
                return null;
            }
 
        }
        public DataSet Get_DDO_by_MaKHANG(string strMa_dviqly, string strMa_khang)
        {
            try
            {
                DataSet ds = new DataSet();
                ds = obj_TRUY_THU_Controller.Get_DDO_by_MaKHANG(strMa_dviqly, strMa_khang);
                return ds;
            }
            catch
            { return null; }
        }

        #endregion

        #region TUNGVT - IntoGCS dat hang

        public DataSet Togcs(Int16 i16NamHD, Int16 i16ThangHD, Int16 i16Ky, string strMa_dviqly, string strMa_sogcs, string strMa_khang, ref string strErr)
        {
            try
            {
                DataSet ds = new DataSet();
                ds = obj_NPC_INTOGCS_Controller.TH_INTOGCS(i16NamHD, i16ThangHD, i16Ky, strMa_dviqly, strMa_sogcs, strMa_khang, ref strErr);
                return ds;
            }
            catch
            {
                return null;
            }
        }

        public string hell()
        {
            return "hell";
        }

        #endregion

        #region TUNGVT - IntoGCS NPC

        public DataSet TogcsNPC_Co(Int16 i16NamHD, Int16 i16ThangHD, Int16 i16Ky, string strMa_dviqly, string strMa_sogcs, string strMa_khang, string strLoaiCto, ref string strErr)
        {
            try
            {
                DataSet ds = new DataSet();
                ds = obj_NPC_INTOGCS_Controller.TogcsNPC_Co(i16NamHD, i16ThangHD, i16Ky, strMa_dviqly, strMa_sogcs, strMa_khang, strLoaiCto, ref strErr);
                return ds;
            }
            catch
            {
                return null;
            }
        }

        public DataSet TogcsNPC_Dtu(Int16 i16NamHD, Int16 i16ThangHD, Int16 i16Ky, string strMa_dviqly, string strMa_sogcs, string strMa_khang, string strLoaiCto, ref string strErr)
        {
            try
            {
                DataSet ds = new DataSet();
                ds = obj_NPC_INTOGCS_Controller.TogcsNPC_Dtu(i16NamHD, i16ThangHD, i16Ky, strMa_dviqly, strMa_sogcs, strMa_khang, strLoaiCto, ref strErr);
                return ds;
            }
            catch
            {
                return null;
            }
        }

        public DataSet TogcsNPC_All(Int16 i16NamHD, Int16 i16ThangHD, Int16 i16Ky, string strMa_dviqly, string strMa_sogcs, string strMa_khang, string strLoaiCto, ref string strErr)
        {
            try
            {
                DataSet ds = new DataSet();
                ds = obj_NPC_INTOGCS_Controller.TogcsNPC_All(i16NamHD, i16ThangHD, i16Ky, strMa_dviqly, strMa_sogcs, strMa_khang, strLoaiCto, ref strErr);
                return ds;
            }
            catch
            {
                return null;
            }
        }

        public DataSet DanhsachKHSogcs(string strMa_dviqly, string strMa_sogcs, string strMa_khang, ref string strErr)
        {
            try
            {
                DataSet ds = new DataSet();
                ds = obj_NPC_INTOGCS_Controller.DanhsachKHSogcs(strMa_dviqly, strMa_sogcs, strMa_khang, ref strErr);
                return ds;
            }
            catch
            {
                return null;
            }
        }

        public DataSet TogcsNPC_Co_DNGUON(Int16 i16NamHD, Int16 i16ThangHD, Int16 i16Ky, string strMa_dviqly, string strMa_sogcs, string strMa_khang, string strLoaiCto, ref string strErr)
        {
            try
            {
                DataSet ds = new DataSet();
                ds = obj_NPC_INTOGCS_DNGUON_Controller.TogcsNPC_Co(i16NamHD, i16ThangHD, i16Ky, strMa_dviqly, strMa_sogcs, strMa_khang, strLoaiCto, ref strErr);
                return ds;
            }
            catch
            {
                return null;
            }
        }

        public DataSet TogcsNPC_Dtu_DNGUON(Int16 i16NamHD, Int16 i16ThangHD, Int16 i16Ky, string strMa_dviqly, string strMa_sogcs, string strMa_khang, string strLoaiCto, ref string strErr)
        {
            try
            {
                DataSet ds = new DataSet();
                ds = obj_NPC_INTOGCS_DNGUON_Controller.TogcsNPC_Dtu(i16NamHD, i16ThangHD, i16Ky, strMa_dviqly, strMa_sogcs, strMa_khang, strLoaiCto, ref strErr);
                return ds;
            }
            catch
            {
                return null;
            }
        }

        public DataSet get_TT_SOGCS(string strMa_dviqly, string strMa_sogcs)
        {
            try
            {
                DataSet ds = new DataSet();
                ds = obj_NPC_INTOGCS_DNGUON_Controller.get_TT_SOGCS(strMa_dviqly, strMa_sogcs);
                return ds;
            }
            catch
            {
                return null;
            }
        }

        public DataSet get_D_SOGCS(string strMadviqly, ref string strErr)
        {
            try
            {
                var a = obj_NPC_INTOGCS_Controller.select_D_SOGCS_All(strMadviqly, ref strErr);
                var b = obj_NPC_INTOGCS_Controller.select_TT_SOGCS_All(strMadviqly, ref strErr);
                if (a == null)
                {
                    return null;
                }

                if (b == null)
                {
                    return null;
                }

                var s = (from p in a
                         select new
                         {
                             MA_SEARCH = p.MA_SOGCS,
                             SEARCH = p.MA_SOGCS + " - " + p.TEN_SOGCS,
                             TEN_SEARCHED = p.TEN_SOGCS
                         }).ToList();

                var t = (from p in b
                         select new
                         {
                             MA_SEARCH = p.MA_SOGCS,
                             SEARCH = p.MA_SOGCS + " - " + p.TEN_SOGCS,
                             TEN_SEARCHED = p.TEN_SOGCS
                         }).ToList();

                var q = s.Union(t).ToList();

                if (q != null && q.Count > 0)
                {
                    DataTable dt = Utility.LINQToDataTable(q);
                    dt.TableName = "D_SOGCS";
                    dt.AcceptChanges();
                    DataSet ds = new DataSet();
                    ds.Tables.Add(dt);
                    return ds;
                }
                else
                {
                    return null;
                }
            }
            catch (Exception ex)
            {
                strErr = ex.Message;
                return null;
            }

        }

        #endregion

        # region Trinhky

        #endregion
    }
}
